solution.cpp 1.3 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <iostream>
using namespace std;
const int N = 55;
const int MOD = 1e9 + 7;
int dp[N][N][13][14];
int g[N][N];
int n, m, k;
int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> g[i][j];
            g[i][j]++;
        }
    }
    dp[1][1][1][g[1][1]] = 1;
    dp[1][1][0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            for (int u = 0; u <= k; u++)
            {
                for (int v = 0; v <= 13; v++)
                {
                    dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD;
                    dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD;
                    if (u > 0 && v == g[i][j])
                    {
                        for (int c = 0; c < v; c++)
                        {
                            dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][c]) % MOD;
                            dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD;
                        }
                    }
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= 13; i++)
        res = (res + dp[n][m][k][i]) % MOD;
    cout << res << endl;
    return 0;
}