超级楼梯

#include<stdio.h>
int fun(int x)
{
 if(x==1)
 return 1;
 else if(x==2)
 return 1;
 else if(x==3)
 return 2;
 else 
 return fun(x-1)+fun(x-2);
}
int main( )
{
    int N,t;
    scanf("%d",&N);
    while(N--)
    {
     scanf("%d",&t);
     printf("%d\n",fun(t));
    }
    return 0;
}

超时。。TLE …

看来需要打表。。

#include<stdio.h>
int A[60]={0,1,1,2};
int main( )
{
    int N,t,i,j,sum;
    scanf("%d",&N);
    while(N--)
    {
     scanf("%d",&t);
     for(i=4;i<=t;i++)
     A[i]=A[i-1]+A[i-2];
     printf("%d\n",A[t]);
    }
    return 0;
}
果断AC…

posted on 2011-04-29 19:59  more think, more gains  阅读(207)  评论(0编辑  收藏  举报

导航