文章

59

粉丝

0

获赞

361

访问

44.3k

头像
N阶楼梯上楼问题 题解:long long+step[++x]=step[x-2]+step[x-1]

#include <iostream>
using namespace std;

int main()
{
	int N;
	while(cin>>N)
	{
		long long step[95]={0};
		step[1]=1;
		step[2]=2;
		if(N>2)
		{
			int x=2;
			while(x!=N)
				step[++x]=step[x-2]+step[x-1];
		}
		cout<<step[N]<<endl;
	}
	return 0;
}
				
			

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发