全部评论 3

  • 递推吧

    dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1];
    

    3天前 来自 浙江

    1
    • 两边的传过来

      1 0 1 0
         |
         v
      0 1 0 1
      

      3天前 来自 浙江

      1
  • 比如这样

    #include <bits/stdc++.h>
    using namespace std;
    
    int n, m, idx=0, cnt=0;
    
    void dfs(int a, int idx){
        if(idx==m){
            if(a==1)
                cnt++;
            return;
        }
        if(a==n)
            dfs(1, idx+1);
        else
            dfs(a+1, idx+1);
        if(a==1)
            dfs(n, idx+1);
        else
            dfs(a-1, idx+1);
    }
    
    int main(){
        cin >> n >> m;
        dfs(1, idx);
        cout << cnt;
    }
    

    2026-08-17 来自 辽宁

    0
  • 递归有4组TLE(到后来时间复杂度指数级爆炸)

    2026-08-17 来自 辽宁

    0

热门讨论