用递归写的,50分,求教!!!
  • 板块P1255 数楼梯
  • 楼主ZJLmath
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/8/27 13:16
  • 上次更新2023/10/27 13:28:26
查看原帖
用递归写的,50分,求教!!!
764672
ZJLmath楼主2022/8/27 13:16
#include<iostream>
using namespace std;
int f(int h){
	if(h==0)return 0;
	if(h==2)return 2;
	if(h==1)return 1;
	return f(h-1)+f(h-2);
}
int main(){
	int n;
	cin>>n;
	cout<<f(n);
	return 0;
}

2022/8/27 13:16
加载中...