HDU 2041

http://acm.hdu.edu.cn/showproblem.php?pid=2041
斐波那契

超级楼梯

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31691    Accepted Submission(s): 16344


Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
 

Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
 

Output
对于每个测试实例,请输出不同走法的数量
 

Sample Input
 
     
2 2 3
 

Sample Output
 
     
1 2
 

Author
lcy
 

Source
2005实验班短学期考试
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2044  2050  2049  1297  2048 
 

 
    

 #include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define maxn 1000010
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
}
ll a[4];
int n;
ll fobonaxi(int n)
{
a[1]=1;
a[2]=2;
if(n==1)a[3]=1;
else if(n==2)a[3]=2;
for(int i=3;i<=n;i++)
{
a[3]=a[1]+a[2];
a[1]=a[2];
a[2]=a[3];
}
return a[3];
}
int main()
{
int t;
while(~scanf("%d",&t))
{
for(int i=1;i<=t;i++)
{
scanf("%d",&n);
printf("%I64d\n",fobonaxi(n-1));
}
}
return 0;
}

你可能感兴趣的:(HDU 2041)