杭电2041题
//超级楼梯
//思路:使用递推求解 p[n] = p[n-1] + p[n-2]
#include <iostream>
using namespace std;
int main()
{
int case_number;
cin>>case_number;
for(int i=0;i<case_number;i++)
{
int m;
cin>>m;
if(m==2)
cout<<1<<endl;
else if(m==3)
cout<<2<<endl;
else
{
int *p = new int[m];
p[0] = 0;
p[1] = 1;
p[2] = 2;
for(int j=3;j<m;j++)
{
p[j] = p[j-1] + p[j-2];
}
//注意:输的是p[j-1]而不是p[j]
cout<<p[j-1]<<endl;
delete []p;
}
}
return 0;
}