n级台阶,每次可走一台阶或两台阶,从0到n有多少方案
#include<bits/stdc++.h>
using namespace std;
int n;
int fb(int t){
if(t==1)return 1;
if(t==2)return 2;
return fb(t-1)+fb(t-2);
}
int main(){
cin>>n;
cout<<fb(n);
return 0;
}
n级台阶,每次可走一台阶或两台阶,从0到n有多少方案
#include<bits/stdc++.h>
using namespace std;
int n;
int fb(int t){
if(t==1)return 1;
if(t==2)return 2;
return fb(t-1)+fb(t-2);
}
int main(){
cin>>n;
cout<<fb(n);
return 0;
}