#include<iostream>
using namespace std;
int n;
int timeSum;
void DFS(int step_number)
{
if (step_number == n)
{
timeSum++;
return;
}
for (int i = 1; i <= 2; i++)
{
step_number += i;
if(step_number<=n) DFS(step_number);
step_number -= i;//回溯
}
}
int main()
{
cin >> n;
DFS(0);
cout << timeSum;
return 0;
}
跳台阶问题(递归与基于二叉树的DFS)
于 2024-07-23 17:23:02 首次发布