~题目链接~
http://poj.org/problem?id=2506
输入
2 8 12 100 200
结果
3 171 2731 845100400152152934331135470251 1071292029505993517027974728227441735014801995855195223534251
递推+高精度 f[n]=f[n-1]+2*f[n-2]
#include<stdio.h> #include<string.h> int main() { int s[261][261];//注意把数组开大一点,250取到 int i,j,n,m,k=0; memset(s,0,sizeof(s)); s[1][0]=1; s[2][0]=3; for(i=3;i<=260;i++) for(j=0;j<=260;j++) { m=s[i-1][j]+2*s[i-2][j]+k; s[i][j]=m%10; k=m/10; } int leap=0; while(scanf("%d",&n)!=EOF) { leap=0; if(n==0) { printf("1 "); continue; } for(i=260;i>=0;i--) { if(s[n][i]||leap) { leap=1; printf("%d",s[n][i]); } else continue; } printf(" "); } return 0; }