rt,感觉是一个暴力的 dp,但是样例 3 过不去,可以水 sub0,sub1。
怀疑 k 较大的时候有问题。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 105;
int n, m, k, p, s, a[N][N], x, y, f[N][N][N], g[N][N][N], h[N][N], ans;
inline void calc(int sx, int sy){
if(a[sx][sy]) return ;
for(int i = sx; i <= n; i++){
for(int j = sy; j <= m; j++) h[i][j] = 0;
}
h[sx][sy] = 1;
for(int i = sx; i <= n; i++){
for(int j = sy; j <= m; j++){
if(a[i][j]) continue ;
if(i + j - sx - sy > k) continue ;
if(i != sx) h[i][j] += h[i - 1][j];
if(j != sy) h[i][j] += h[i][j - 1];
h[i][j] %= p;
}
}
for(int i = sx; i <= n; i++){
for(int j = sy; j <= m; j++){
if(i + j - sx - sy > k) continue ;
(g[sx][sy][i + j - sx - sy] += h[i][j]) %= p;
}
}
}
signed main(){
scanf("%lld%lld%lld%lld%lld", &n, &m, &k, &p, &s);
for(int i = 1; i <= s; i++){
scanf("%lld%lld", &x, &y);
a[x][y] = 1;
}
if(a[1][1] == 1 || a[n][m] == 1){
printf("0\n");
return 0;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
calc(i, j);
}
}
f[1][1][0] = 1;
for(int stp = 0; stp <= k; stp++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i][j] == 1) continue ;
(f[i][j][stp] += f[i - 1][j][stp] + f[i][j - 1][stp]) %= p;
for(int kk = 1; kk <= k - stp; kk++){
(f[i][j][kk + stp] += f[i][j][stp] * g[i][j][kk] % p) %= p;
}
}
}
}
for(int stp = 0; stp <= k; stp++) (ans += f[n][m][stp]) %= p;
printf("%lld\n", ans);
return 0;
}
/*
1 5 2 998244353 0
*/
可惜了,离 AK 最近的一次。