当前位置:网站首页>Fibonacci number of dynamic programming
Fibonacci number of dynamic programming
2022-07-07 23:29:00 【Little brother who loves Python】
Dynamic programming
Fibonacci number
/* Fibonacci sequence */
public class Fit {
public static int fit(int n){
if(n<2){
return n;
}
int[] dp = new int[n+1];
// Initialization of boundary value
dp[1] = 1;
for (int i = 2; i <= n ;i++){
// State transition equation
dp[i] = dp[i-1] + dp[i-2];
}
return dp[n];
}
public static void main(String[] args) {
int num = 0;
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()){
num = scanner.nextInt();
fit(num);
System.out.println(fit(num));
}else{
System.out.println(" The input is not a natural number !");
}
}
}```
边栏推荐
- Turbo introder common scripts
- Talk about the design and implementation logic of payment process
- USB (XVII) 2022-04-15
- Design and implementation of spark offline development framework
- leetcode-520. Detect capital letters -js
- 进度播报|广州地铁七号线全线29台盾构机全部完成始发
- Unity3d learning notes 5 - create sub mesh
- USB (XVIII) 2022-04-17
- How to login and enable synchronization function in Google browser
- 包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
猜你喜欢
Matlab-SEIR传染病模型预测
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
UE4_UE5结合罗技手柄(F710)使用记录
LDO稳压芯片-内部框图及选型参数
Unity3D学习笔记6——GPU实例化(1)
Matlab 信号处理【问答随笔·2】
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
In the field of software engineering, we have been doing scientific research for ten years!
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
ROS2专题(03):ROS1和ROS2的区别【02】
随机推荐
Oracle database backup and recovery
In the field of software engineering, we have been doing scientific research for ten years!
LDO稳压芯片-内部框图及选型参数
USB (XVI) 2022-04-28
Have all the fresh students of 2022 found jobs? Is it OK to be we media?
B_QuRT_User_Guide(37)
欢聚时代一面
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
Adrnoid Development Series (XXV): create various types of dialog boxes using alertdialog
LDO voltage stabilizing chip - internal block diagram and selection parameters
VS扩展工具笔记
v-for遍历对象
Summary of SQL single table query 2020.7.27
php 使用阿里云存储
LeeCode -- 6. Zigzag transformation
Oracle-数据库的备份与恢复
turbo intruder常用脚本
产业共融新势能,城链科技数字峰会厦门站成功举办
HDU 4747 Mex「建议收藏」
The 19th Zhejiang Provincial Collegiate Programming Contest 2022浙江省赛 F.EasyFix 主席树