hdu1028 Ignatius and the Princess III

OI 数学
文章目录

生成函数看:

rabbithu

推fibonacci通项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[125], b[125];
int main(){
while(scanf("%d", &n)!=EOF){
for(int i=0; i<=n; i++){
a[i] = 1;
b[i] = 0;
}
for(int i=2; i<=n; i++){
for(int j=0; j<=n; j++)
for(int k=0; k+j<=n; k+=i)
b[j+k] += a[j];
for(int j=0; j<=n; j++){
a[j] = b[j];
b[j] = 0;
}
}
printf("%d\n", a[n]);
}
return 0;
}