X 国王有一个地宫宝库，是 n×m 个格子的矩阵，每个格子放一件宝贝，每个宝贝贴着价值标签。

1≤n,m≤50,
1≤k≤12,
0≤Ci≤12

2 2 2
1 2
2 1

2

2 3 2
1 2 3
2 1 5

14

dp[i][j][cnt][v] = (dp[i][j][cnt][v] + dp[i - 1][j][cnt][v]) % MOD; dp[i][j][
cnt][v] = (dp[i][j][cnt][v] + dp[i][j - 1][cnt][v]) % MOD;

= 1，拿这个物品dp[1][1][1][w[1][1]]

#include <iostream> using namespace std; const int N = 55; const int MOD =
1000000007; int dp[N][N][15][15]; int w[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 >> w
[i][j]; w[i][j]++; } dp[1][1][0][0] = 1; dp[1][1][1][w[1][1]] = 1; for (int i =
1; i <= n; i++) for (int j = 1; j <= m; j++) for (int cnt = 0; cnt <= k; cnt++)
for (int v = 0; v <= 13; v++) { dp[i][j][cnt][v] = (dp[i][j][cnt][v] + dp[i - 1]
[j][cnt][v]) % MOD; dp[i][j][cnt][v] = (dp[i][j][cnt][v] + dp[i][j - 1][cnt][v])
% MOD; if (cnt > 0 && w[i][j] == v) { for (int s = 0; s < v; s++) { dp[i][j][cnt
][v] = (dp[i][j][cnt][v] + dp[i - 1][j][cnt - 1][s]) % MOD; dp[i][j][cnt][v] = (
dp[i][j][cnt][v] + dp[i][j - 1][cnt - 1][s]) % MOD; } } } int res = 0; for (int
i= 0; i <= 13; i++) { res = (res + dp[n][m][k][i]) % MOD; } cout << res << endl;
return 0; }