当前位置:网站首页>5. Dynamic programming -- Fibonacci series
5. Dynamic programming -- Fibonacci series
2022-07-28 10:16:00 【[email protected]】
Title Description :f(0) = 0, f(1) = 1,f(n) = f(n - 1) + f(n - 2), among n> 1. The answer needs to be modelled
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;
}
Dynamic programming algorithm is
- For a scale of n The problem of , Break it down into k A smaller sub problem ( Stage ), Solve the subproblems in order , The solution of the previous subproblem , It provides useful information for the solution of the latter subproblem . In solving any subproblem , The local optimal solution is obtained through decision-making , Solve each sub problem in turn . Finally, you can make a simple judgment , Get the solution of the original problem .

版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224678.html
边栏推荐
- Illustrate three mainstream enterprise architecture models (recommended collection!)
- 9、删除链表中节点
- Context values traps and how to avoid or mitigate these traps in go
- 巧用ngx_lua做流量分组
- 死锁算法:银行家算法和安全性算法
- [learning notes] border and period
- Continue to write the greatest work based on modelarts [play with Huawei cloud]
- UEditor V1.4.3控制文件压缩
- Talk about the problem of preventing others from debugging websites through console based on JS implementation
- 安装gmp
猜你喜欢

剑指offer

2022 uni app parsing token standard - use jsrsasign - climb the pit

Voice chat app - how to standardize the development process?

Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation

Flink - checkpoint Failure reason: Not all required tasks are currently running

Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment

记录一次idea中的父子项目修改project与module名称,亲测!

5、动态规划---斐波那契数列

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

Thinking and summary of technical personnel | R & D Efficiency
随机推荐
Tencent technical experts: decrypt the 100 million user products wechat, QQ, King glory... Comprehensively practice on the cloud!
Redis design specification
Description of landingsite electronic label quppa firmware entering DFU status
Detailed explanation of thread synchronization volatile and synchronized
Skiasharp's WPF self drawn drag ball (case version)
Detailed explanation of super complete knowledge points of instruction system
Context values traps and how to avoid or mitigate these traps in go
Oracle中的小知识
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC
Leetcode -- minimum number of rotation array
【云驻共创】华为云:MetaStudio数字内容生产线,让虚拟世界与现实世界无缝融合
Digital construction of pharmaceutical industry is on the verge
office2013以上输入数学公式
巧用ngx_lua做流量分组
中芯国际科创板IPO顺利过会,市值有望突破2000亿!
2021-10-13arx
Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
Performance test of API gateway APIs IX in Google cloud T2a and T2D
10 minute quick start EVs [play Huawei cloud]
[openharmony] [rk2206] build openharmony compiler (2)