当前位置:网站首页>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 !");
}
}
}```
边栏推荐
- Lm12 rolling heikin Ashi double K-line filter
- VS扩展工具笔记
- The 19th Zhejiang Provincial Collegiate Programming Contest VP记录+补题
- Solution: prompt "unsupported video format" when inserting avi format video into the message
- JS get the key and value of the object
- RE1 attack and defense world reverse
- 建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
- 2021ICPC上海 H.Life is a Game Kruskal重构树
- B_ QuRT_ User_ Guide(36)
- B_QuRT_User_Guide(39)
猜你喜欢
Three questions TDM
PCB wiring rules of PCI Express interface
Explain
LDO穩壓芯片-內部框圖及選型參數
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
2021ICPC上海 H.Life is a Game Kruskal重构树
JS get the key and value of the object
Description of longitude and latitude PLT file format
[compilation principle] lexical analysis design and Implementation
re1攻防世界逆向
随机推荐
B_QuRT_User_Guide(36)
PCI-Express接口的PCB布线规则
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
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
Markdown
FPGA basics catalog
php 使用阿里云存储
SAP HR 社会工作经历 0023
【编译原理】词法分析设计实现
Tree background data storage (using webmethod) [easy to understand]
USB (XVI) 2022-04-28
js 获取对象的key和value
B_QuRT_User_Guide(39)
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
[compilation principle] lexical analysis design and Implementation
HDU 4747 Mex「建议收藏」
LM12丨Rolling Heikin Ashi二重K线滤波器
[microservices SCG] gateway integration Sentinel
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
Experience sharing of system architecture designers in preparing for the exam: the direction of paper writing