文章

59

粉丝

0

获赞

262

访问

5.7k

头像
N阶楼梯上楼问题 题解:long long+step[++x]=step[x-2]+step[x-1]
P1413 华中科技大学/中国矿业大学机试题
发布于2026年3月13日 14:33
阅读数 51

#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;
}
				
			

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发