题目传送门
dp,f[i][j][k][1/0]表示到(i,j)uim/小a魔瓶里的液体为k(经取模后)的方案数
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,m,k,a[801][801],o; int f[801][801][20][2]; long long ans; int main() { scanf("%d%d%d",&n,&m,&k); k++; for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) { scanf("%d",&a[i][j]); f[i][j][a[i][j]%k][0] = 1; } for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) for(int p = 0;p < k; p++) { f[i][j][p][0] = (f[i][j][p][0] + f[i-1][j][(p-a[i][j]+k)%k][1]) % 1000000007; f[i][j][p][0] = (f[i][j][p][0] + f[i][j-1][(p-a[i][j]+k)%k][1]) % 1000000007; f[i][j][p][1] = (f[i][j][p][1] + f[i-1][j][(p+a[i][j])%k][0]) % 1000000007; f[i][j][p][1] = (f[i][j][p][1] + f[i][j-1][(p+a[i][j])%k][0]) % 1000000007; } for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) ans = (ans + f[i][j][0][1]) % 1000000007; printf("%lld",ans); return 0; }