2 条题解

  • -1
    @ 2024-12-12 13:19:22
    • -1
      @ 2024-11-28 17:47:42

      本题考察深度优先搜索算法的使用,使用深度优先搜索一个一个的枚举出有多少种走法。 代码附上:

      #include<iostream>
      #include<string>
      using namespace std;
      int n,ans;
      void dfs(int i){//深度优先搜索
      	if(i==n){
      		ans++;return ;
      	}
      	if(i+2<=n){dfs(i+2);}//走一步
      	if(i+1<=n){dfs(i+1);}//走两步
      }
      int main(){
      	cin>>n;
      	dsf(0);//调用函数
      	cout<<ans;
      	return 0;
       } 
      
      
      • 1

      信息

      ID
      9
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      递交数
      15
      已通过
      9
      上传者