标签:hdu1978
1 6 6 4 5 6 6 4 3 2 2 3 1 7 2 1 1 4 6 2 7 5 8 4 3 9 5 7 6 6 2 1 5 3 1 1 3 7 2
3948
#include <stdio.h>
#include <string.h>
#define maxn 102
const int mod = 1e4;
int dp[maxn][maxn], que[maxn * maxn << 1];
int G[maxn][maxn];
int main() {
freopen("stdin.txt", "r", stdin);
int T, N, M, i, j, front, back, x, y, t;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &N, &M);
for (i = 1; i <= N; ++i)
for (j = 1; j <= M; ++j)
scanf("%d", &G[i][j]);
memset(dp, 0, sizeof(dp));
dp[1][1] = 1;
for (i = 1; i <= N; ++i)
for (j = 1; j <= M; ++j) {
t = dp[i][j]; dp[i][j] = 0;
for (x = 0; x <= G[i][j]; ++x)
for (y = G[i][j] - x; y >= 0; --y)
if (i + x <= N && j + y <= M) {
dp[i+x][j+y] += t;
if (dp[i+x][j+y] >= mod) dp[i+x][j+y] -= mod;
}
}
printf("%d\n", dp[N][M]);
}
return 0;
}标签:hdu1978
原文地址:http://blog.csdn.net/chang_mu/article/details/43198301