3 solutions
-
2
114514
#include<iostream> using namespace std; //b[i]:第i个月卵的数量 long long a[101] = {0}, b[101] = {0}; int main() { int i, x, y, z; cin >> x >> y >> z; //建立初始条件 for(i = 1; i <= x; i++) { //第i个月成虫数量 a[i] = 1; //第i个月卵的数量 b[i] = 0; } //递推 for(i = x + 1; i <= z + 1; i++) { //计算产卵数量 b[i] = y * a[i - x]; a[i] = a[i - 1] + b[i - 2]; } cout << a[z + 1] << endl; return 0; }
-
2
#include<iostream> using namespace std; long long a[101] = {0}, b[101] = {0}; int main() { int i, x, y, z; cin >> x >> y >> z; for(i = 1; i <= x; i++) { a[i] = 1; b[i] = 0; } for(i = x + 1; i <= z + 1; i++) { b[i] = y * a[i - x]; a[i] = a[i - 1] + b[i - 2]; } cout << a[z + 1] << endl; return 0; }
-
1
#include<bits/stdc++.h> using namespace std; long long s[100010]; long long w[100010]; int main(){ int a,b,c; cin>>a>>b>>c; fill(1+w,1+w+a,1);//1-a月的成虫数量为1 fill(1+s,1+s+a,0);//1-a月的虫卵数量为0 for(int i=a+1;i<=c+1;i++){ //w[i-a]表示i-a个月前成虫的数量 s[i]=b*w[i-a];//这个月有b*(i-a)个虫卵 w[i]=w[i-1]+s[i-2];//成虫第一个月不虫卵,从i-2开始计算 } cout<<w[c+1]; return 0; }
- 1
Information
- ID
- 797
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 128
- Accepted
- 44
- Uploaded By