超级楼梯HDOJ2041
超級樓梯
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 71555????Accepted Submission(s): 36480
Input 輸入數(shù)據(jù)首先包含一個整數(shù)N,表示測試實例的個數(shù),然后是N行數(shù)據(jù),每行包含一個整數(shù)M(1<=M<=40),表示樓梯的級數(shù)。
Output 對于每個測試實例,請輸出不同走法的數(shù)量
Sample Input 2 2 3
Sample Output 1 2
Author lcy
先找?guī)捉M數(shù)據(jù)找規(guī)律發(fā)現(xiàn):
M????? 走法
1? ?0
2? ?1
3? ?24? ?3
5? ?5
6? ?8
當(dāng)M大于等于4的時候每一項都是前第一項和前第兩項的和于是:
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
int func (int m)
{
? ? int data[500]={0,0,1,2};
? ? if(m==1)
? ? ? ? return 0;
? ? ? ? if(m==2)
? ? ? ? ? ? return 1;
? ? ? ? if(m==3)
? ? ? ? ? ? return 2;
? ? for(int i=4;i<=m;i++)
? ? {
? ? ? ? data[i]=data[i-1]+data[i-2];
? ? }
? ? return data[m];
}
int main ()
{
int n;
while(cin>>n)
{
? ? int data[50];
? ? if(n>=1&&n<=40)
? ? {
? ? ? ? ? for(int i=1;i<=n;i++)
? ? {
? ? ? ? cin>>data[i];
? ? }
? ? for(int i=1;i<=n;i++)
? ? {
? ? ? ? cout<<func(data[i])<<endl;
? ? }
? ? }
}
? ? return 0;
}
總結(jié)
以上是生活随笔為你收集整理的超级楼梯HDOJ2041的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据技术之kafka (第 3 章 K
- 下一篇: mysql web备份软件_GitHub