#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int Max = 7500;
int ans[Max][750],len[Max];
void init()
{
int i,j;
memset(ans,0,sizeof(ans));
memset(len,0,sizeof(len));
ans[1][0] = 1,len[1] = 1;
ans[2][0] = 1,len[2] = 1;
ans[3][0] = 1,len[3] = 1;
ans[4][0] = 1,len[4] = 1;
int t;
for( i = 5; i < Max; i ++ )
{
len[i] = len[i−1];
for( j = 0; j < len[i−1]; j ++ )
{
t = ans[i−1][j] + ans[i−2][j] + ans[i−3][j] + ans[i−4][j];
ans[i][j] += t % 10000;
t /= 10000;
if(t)
{
ans[i][j+1] += t;
len[i] = max(len[i],j+2);
}
}
}
}
int main()
{
int n,i;
init();
while(~scanf("%d",&n))
{
i=len[n]−1;
printf("%d",ans[n][i−−]);
for(;i>=0;i−−)
printf("%04d",ans[n][i]);
printf("\n");
}
return 0;
}
一道大数题,当做个用数组存大数的模板了
最新推荐文章于 2019-01-23 11:00:38 发布