1 条题解

  • 0
    @ 2021-6-15 12:50:56

    C++ :

    #include <cstdlib>
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std;
    const int MOD = int(1e9)+7;
    int dp[1005][1005];
    int N;
    void solve() {
        dp[0][0] = 1;
        for (int i = 1; i <= 1000; ++i)
            {
              for (int j = 0; j <= 1000; ++j)
              {
                if (j + 1 <= 1000)
                {
                    dp[i][j] = dp[i-1][j+1];
                    dp[i][j] %= MOD;
                }
                if (j - 2 >= 0)
                {
                    dp[i][j] += dp[i-1][j-2];
                    dp[i][j] %= MOD;
                    if (j == 2)
                    {
                        dp[i][j] += dp[i-1][j-2];
                        dp[i][j] %= MOD;
                    }
                }
             }
        }
    }
    int main() {
        solve();
        while (scanf("%d", &N), N!=-1)
            {
            printf("%d\n", dp[N][0]);
            }
        return 0;
    }
    
    
    • 1

    信息

    ID
    467
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者