/* 问题:走楼梯(递归算法) Time:20160403 author:Alex */ #include <stdio.h> #define MAX_N 41 //递归算法,n的次数可由n-1与n-2来决定 _int64 Step_cal(int M) { int step; _int64 Dp[MAX_N]={0,0,1,2}; if(M < 4) { printf("%I64d\n",Dp[M]); } else { for(step=4;step <=M;step ++)//实现递归计算 { Dp[step] = Dp[step-1]+Dp[step-2]; } printf("%I64d\n",Dp[M]); } return Dp[M]; } int main() { int Step=0; int Count = 0; scanf("%d",&Count); while(Count--) { scanf("%d",&Step); Step_cal(Step); } return 0; }