qwq普通动态规划
f[i][j][k][0/1]走到点(i,j)小a和uim的差值为k 当前这一步是小a/uim走的
只是不知道为什么我注释掉的那坨由当前更新后面会错qwq
#include<bits/stdc++.h> using namespace std; #define Max(x,y) (x)<(y)?(y):(x) #define Min(x,y) (x)<(y)?(x):(y) #define ll long long #define rg register const int N=800+5,M=1000000+5,inf=0x3f3f3f3f,P=1e9+7; const int power=4,base=10000; int n,m,k,ans=0,a[N][N],f[N][N][20][2]; template <class t>void rd(t &x){ x=0;int w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=w?-x:x; } int main(){ freopen("in.txt","r",stdin); rd(n),rd(m),rd(k); memset(f,0,sizeof(f)); ++k; for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) rd(a[i][j]),a[i][j]%=k,f[i][j][a[i][j]][0]=1; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ for(int kk=0;kk<=k;++kk){ /* f[i+1][j][(kk+a[i+1][j])%k][0]=(f[i+1][j][(kk+a[i+1][j])%k][0]+f[i][j][kk][1])%P; f[i][j+1][(kk+a[i+1][j])%k][0]=(f[i][j+1][(kk+a[i+1][j])%k][0]+f[i][j][kk][1])%P; f[i+1][j][(kk-a[i+1][j]+k)%k][1]=(f[i+1][j][(kk-a[i+1][j]+k)%k][1]+f[i][j][kk][0])%P; f[i][j+1][(kk-a[i][j+1]+k)%k][1]=(f[i][j+1][(kk-a[i][j+1]+k)%k][1]+f[i][j][kk][0])%P;*/ f[i][j][kk][0]=(f[i][j][kk][0]+f[i-1][j][(kk-a[i][j]+k)%k][1])%P; f[i][j][kk][0]=(f[i][j][kk][0]+f[i][j-1][(kk-a[i][j]+k)%k][1])%P; f[i][j][kk][1]=(f[i][j][kk][1]+f[i-1][j][(kk+a[i][j])%k][0])%P; f[i][j][kk][1]=(f[i][j][kk][1]+f[i][j-1][(kk+a[i][j])%k][0])%P; } } } for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) ans=(ans+f[i][j][0][1])%P; printf("%d",ans); return 0; }