当前位置:网站首页>Sword finger offer 10- I. Fibonacci sequence
Sword finger offer 10- I. Fibonacci sequence
2022-06-25 15:36:00 【anieoo】
Original link : The finger of the sword Offer 10- I. Fibonacci sequence

solution:
Dynamic programming
class Solution {
public:
int fib(int n) {
if(n < 2) return n;
vector<int> dp(n + 1);
dp[0] = 0;
dp[1] = 1;
for(int i = 2;i <= n;i++) {
dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007;
}
return dp[n];
}
};边栏推荐
- 2.18 codeforces supplement
- GDB debugging
- MySQL performance optimization - index optimization
- Distributed transaction solution
- 55 specific ways to improve program design (1)
- 基于深度Q学习的雅达利打砖块游戏博弈
- MySQL修改字段語句
- Learning C language today is the first time to learn C language. In college, C linguistics is not good, but I want to make progress, so I found a beep video on the Internet to learn C language
- golang reverse a slice
- Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
猜你喜欢

Using R language in jupyter notebook

MySQL transaction characteristics and implementation principle

Graphic control and layout basis of R visualization

Principle and implementation of MySQL master-slave replication (docker Implementation)

QT excel table read / write library - qtxlsx

Distributed transaction solution

How to download and install Weka package

中国高校首次!全球唯一!同济学子斩获国际大奖

GDB debugging

Download and installation tutorial of consumer
随机推荐
Paddlepaddle paper reproduction course biggan learning experience
Mapbox map - inconsistent coordinate system when docking GIS layers?
How to download and install Weka package
[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3
[paper notes] semi supervised object detection (ssod)
[C language] implementation of magic square array (the most complete)
Data preprocessing - normalization and standardization
QT excel table read / write library - qtxlsx
Summary of regularization methods
Install Kali extension 1: (kali resolution problem)
CPU over high diagnosis and troubleshooting
Using R language in jupyter notebook
Solve the go project compilation error go mod: no such file or directory
Distributed transaction solution
Fishing detection software
Is it safe to open a stock account through the account opening link given by the account manager? I want to open an account
How GC determines whether an object can be recycled
Netlogo learning
Image segmentation based on deep learning: network structure design
Detailed description of crontab command format and summary of common writing methods