当前位置:网站首页>5、动态规划---斐波那契数列
5、动态规划---斐波那契数列
2022-07-28 09:58:00 【[email protected]】
题目描述:f(0) = 0, f(1) = 1,f(n) = f(n - 1) + f(n - 2), 其中 n> 1。答案需要取模
1e9+7(1000000007)
public int fib(int n) {
int a = 0, b = 1, sum;
for(int i = 0; i < n; i++){
sum = (a + b) % 1000000007;
a = b;
b = sum;
}
return a;
}
动态规划算法即
- 对于一个规模为n的问题,将其分解为k个规模较小的子问题(阶段),按顺序求解子问题,前一子问题的解,为后一子问题的求解提供了有用的信息。在求解任一子问题时,通过决策求得局部最优解,依次解决各子问题。最后可以通过简单的判断,得到原问题的解。

版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124635400
边栏推荐
猜你喜欢

Illustrate three mainstream enterprise architecture models (recommended collection!)

Skillfully use NGX_ Lua makes traffic grouping

ES (8.1) certification topic

Boss: there are too many systems in the company. Can we realize account interworking?

13 probability distributions that must be understood in deep learning

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control

剑指offer

B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

It's settled! On July 30!
随机推荐
Performance test of API gateway APIs IX in Google cloud T2a and T2D
定了!就在7月30日!
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
21. 合并两个有序链表
Sizebasedtriggingpolicy introduction
web之圣杯和双飞翼布局、float、clear、both
TCP Basics
Which strings will be resolved to null by fastjason?
JS promotion: the underlying principle of flat tiling
Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
(十)defer关键字
Installing MySQL for Linux operating system (centos7)
️雄关漫道真如铁,而今迈步从头越️
每天在岗不足8小时被辞?腾讯前员工追讨1300万加班费等,法院终审获赔9万
CGAL编译错误
[openharmony] [rk2206] build openharmony compiler (2)
Kubernetes
CloudCompare&PCL 匹配点采样一致性抑制
SQL server, MySQL master-slave construction, EF core read-write separation code implementation
不登高山,不知天之高也;不临深溪,不知地之厚也