# 解题思路
记忆化搜索
一个点可以跳到的点,取决于它现在的能量。而且有一个显而易见的性质就是一条可行路径的终点和起点的横坐标之差加上纵坐标之差肯定小于等于起点的能量。
因为跳到一个点之后,能量和之前的点就已经没有关系了,只与现在的点有关,所以不需要传递能量到下一层。
嗯,思路就是酱紫的
# 附上代码
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int HA = 1e4;
inline int read() {
int x = , f = ; char c = getchar();
while (c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while (c <= '' && c >= '') {x = x* + c-''; c = getchar();}
return x * f;
}
int T, n, m, en[][], f[][];
bool vis[][];
inline int dfs(int x, int y) {
if(x > n || y > m || x < || y < ) return ;
if(x == n && y == m) return ;
if(vis[x][y] != false) return f[x][y];
for(int i=; i<=en[x][y]; i++) {
for(int j=; j+i<=en[x][y]; j++) {
int xx = i + x, yy = j + y;
if(xx == x && yy == y) continue;
f[x][y] += dfs(xx, yy);
if(f[x][y] >= HA) f[x][y] %= HA;
}
}
vis[x][y] = true;
return f[x][y];
}
int main() {
T = read();
while (T--) {
memset(vis, , sizeof(vis));
memset(f, , sizeof(f));
n = read(), m = read();
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
en[i][j] = read();
printf("%d\n", dfs(, ) % HA);
}
}