第五届蓝桥杯省赛第九题,地宫取宝问题,难度还真不小。
这个题的限制要求比较多,dp自然比较繁琐,这里采用四个状态f(i, j, k, c)表示在(i, j)这个点上拿了k个物品,物品最大价值为c
由于数据范围很小,五重循环是可以接受的。
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
class Main {
static BufferedReader br;
static PrintWriter pw;
static int N;
static int mod;
static int n;
static int m;
static int k;
static int[][][][] f;
static int[][] w;
Main() {
}
public static void main(String[] args) throws IOException {
String[] s = br.readLine().split(" ");
n = Integer.parseInt(s[0]);
m = Integer.parseInt(s[1]);
k = Integer.parseInt(s[2]);
int i;
int j;
for(i = 1; i <= n; ++i) {
s = br.readLine().split(" ");
for(j = 1; j <= m; ++j) {
w[i][j] = Integer.parseInt(s[j - 1]);
int var10002 = w[i][j]++;
}
}
f[1][1][0][0] = 1;
f[1][1][1][w[1][1]] = 1;
for(i = 1; i <= n; ++i) {
for(j = 1; j <= m; ++j) {
if (i != 1 || j != 1) {
for(int l = 0; l <= k; ++l) {
for(int o = 0; o <= 13; ++o) {
f[i][j][l][o] = (f[i][j][l][o] + f[i - 1][j][l][o]) % mod;
f[i][j][l][o] = (f[i][j][l][o] + f[i][j - 1][l][o]) % mod;
if (l > 0 && w[i][j] == o) {
for(int p = 0; p < o; ++p) {
f[i][j][l][o] = (f[i][j][l][o] + f[i - 1][j][l - 1][p]) % mod;
f[i][j][l][o] = (f[i][j][l][o] + f[i][j - 1][l - 1][p]) % mod;
}
}
}
}
}
}
}
i = 0;
for(j = 0; j < 14; ++j) {
i = (i + f[n][m][k][j]) % mod;
}
pw.println(i);
pw.flush();
pw.close();
br.close();
}
static {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
N = 55;
mod = 1000000007;
f = new int[N][N][15][15];
w = new int[N][N];
}
}