当前位置:网站首页>Sword finger offer 10- ii Frog jumping on steps

Sword finger offer 10- ii Frog jumping on steps

2022-06-11 08:43:00 zmm_ mohua

The finger of the sword Offer 10- II. The problem of frog jumping on the steps

subject

 Insert picture description here

Code

#include <iostream>
#include <vector>
using namespace std; 

int numWays(int n) {
    
	if(n == 0 || n == 1){
    
		return 1;
	}
	vector<int> dp(n);
	dp[0] = 1;
	dp[1] = 2;
	for(int i = 2; i < n; i++){
    
		dp[i] = dp[i-1] + dp[i-2];
		dp[i] %= 1000000007;
	}
	return dp[n-1];
}

int main(){
    
	int n, res;
	cin>>n;
	res = numWays(n);
	cout<<res;
	return 0;
}
原网站

版权声明
本文为[zmm_ mohua]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110827533767.html