训练两年半的“坤坤”有一只会生蛋的“鸡”
2024-11-20 20:43:56
发布于:浙江
阿弥诺斯的代码有两种,分开写;
// 记忆化搜索
#include <iostream>
#include <vector>
using namespace std;
vector <int> memo(501,-1);
int countSequences(int n){
if(n == 1) return 1;
if(memo[n] != -1) return memo[n];
int result = 1;
for(int i = 1;i <= n / 2;++i){
result += countSequences(i);
}
memo[n] = result;
return result;
}
int main(){
int n;
cin >> n;
cout << countSequences(n) << endl;
return 0;
}
//动态规划
// #include <iostream>
// #include <vector>
// using namespace std;
// int countSequences(int n){
// vector<int> dp(n + 1,0);
// dp[1] = 1;
// for(int i = 2;i <= n;i++){
// dp[i] = 1;
// for(int j = 1;j <= i / 2;++j){
// dp[i] += dp[j];
// }
// }
// return dp[n];
// }
// int main(){
// int n;
// cin >> n;
// cout << countSequences(n) << endl;
// return 0;
// }
全部评论 1
阿弥诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺诺斯
昨天 来自 浙江
0
有帮助,赞一个