tips:有一个错点是没有考虑走楼梯超出限制(39级)的情况,若是不考虑的话我们将会搜不到答案,因此我们应该在超出39级台阶的时候return
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int cnt = 0;
void dfs(int step,int all)
{
if(step>39) return;
if(step==39)
{
if(all%2==0) cnt++;
return;
}
dfs(step+1,all+1);
dfs(step+2,all+1);
}
int main()
{
dfs(0,0);
cout<<cnt<<endl;
return 0;
}
要加油哇!!!