题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250
大数相加
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int fib[7050][510];
int main()
{
int i,j,temp=0,n;
for(i=1; i<=4; ++i)
fib[i][1]=1;
for(i=5; i<7050; ++i)
{
for(j=1; j<510; ++j)
{
temp+=fib[i-1][j]+fib[i-2][j]+fib[i-3][j]+fib[i-4][j];
fib[i][j]=temp%10000;
temp/=10000;
}
}
while(temp)
{
fib[i][j++]=temp%10000;
temp/=10000;
}
while(scanf("%d",&n)!=EOF)
{
for(i=500; i>=1; --i)
{
if(fib[n][i]!=0)
break;
}
printf("%d",fib[n][i]);
for(j=i-1; j>=1; --j)
printf("%04d",fib[n][j]);
printf("\n");
}
return 0;
}