水题。。。我在干什么
f[i][j][k][0/1]表示取到(i,j),差值为k,最后一次是0/1取的,
把k=0,最后一维是1的加起来就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=805,mod=1e9+7;
int n,m,g[N][N],f[N][N][16][2],k,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",&g[i][j]),f[i][j][g[i][j]%k][0]=1;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) for(int K=0;K<k;K++){
if(i+1<=n) {
f[i+1][j][(K+g[i+1][j])%k][0]=(f[i+1][j][(K+g[i+1][j])%k][0]+f[i][j][K][1])%mod;
f[i+1][j][(K-g[i+1][j]+k)%k][1]=(f[i+1][j][(K-g[i+1][j]+k)%k][1]+f[i][j][K][0])%mod;
}
if(j+1<=m) {
f[i][j+1][(K+g[i][j+1])%k][0]=(f[i][j+1][(K+g[i][j+1])%k][0]+f[i][j][K][1])%mod;
f[i][j+1][(K-g[i][j+1]+k)%k][1]=(f[i][j+1][(K-g[i][j+1]+k)%k][1]+f[i][j][K][0])%mod;
}
if(!K) ans=(ans+f[i][j][K][1])%mod;
}
cout<<ans;
}