文章

35

粉丝

599

获赞

6

访问

294.6k

头像
又数据加强了吗 过不了50%
P1685 中南大学2019年机试题
发布于2020年5月9日 22:34
阅读数 10.0k

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int maxn=1e6+1;
const int p=1e9+7;
int dp[maxn];
int main() {
	int n;
	while(cin>>n){
		memset(dp, 0, sizeof(dp));
		dp[1]=1;
		dp[2]=2;
		for(int i=3;i<=n;i++){
			dp[i]=dp[i-1]%p+dp[i-2]%p;
		}
		cout<<dp[n]<<endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

2 条评论
admin SVIP
2020年5月10日 21:59

有多次查询,在循环处理一次就行,预处理的思想

赞(2)

chenziyi : 回复 admin: 非常感谢 很有用~

2020年5月10日 22:20