(Do not point I am not the subject)
This question can easily see is a dp (dp hurdle because it is in looking)
A little think about yy can be a good state:
Number of f [i] [j] [k] [0/1] Representative reached the point (i, j), the amount of the liquid membrane phase difference k (small-uim a = k), small a / uim taken last case
A pit:
F [ 850 ] [ 850 ] [ 20 is ] [ 2 ]: Accepted 100 2 .00s 103 .31MB F [ 850 ] [ 850 ] [ 25 ] [ 2 ]: unaccepted 85 . 1 .11s 125 .00MB // MLE three points
Transfer also do well: a point may only coming from the left or top
int tmp=(c-mp[i][j]+k)%k; f[i][j][c][0]+=(f[i-1][j][tmp][1]%mod+f[i][j-1][tmp][1]%mod)%mod; f[i][j][c][0]%=mod; tmp=(c+mp[i][j])%k; f[i][j][c][1]+=(f[i-1][j][tmp][0]%mod+f[i][j-1][tmp][0]%mod)%mod; f[i][j][c][1]%=mod;
Wherein the liquid film on a point of difference between the representative tmp
Pit II: liquid volume may be greater than the film at the time of input k
Pit III: can start from any point, should each f [i] [j] [mp [i] [j]] [0] value of 1
Four pit: c-mp [i] [j] may be negative, if not written tmp = (c-mp [i] [j] + k)% k but tmp = (c-mp [i] [j ])% k, then,
Unaccepted 10 2.01s 103.01MB
Not much to say, look at the code
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 int n-, m, K, MP [ 850 ] [ 850 ]; . 4 // pit a: bomb space . 5 int F [ 850 ] [ 850 ] [ 20 is ] [ 2 ], SUM; . 6 #define MOD 1000000007 . 7 int main () { . 8 iOS :: sync_with_stdio ( 0 ); . 9 CIN >> >> m >> n- K; 10 K ++ ; . 11 // read 12 is for( Int I = . 1 ; I <= n-; I ++ ) { 13 is for ( int J = . 1 ; J <= m; J ++ ) { 14 CIN >> MP [I] [J]; 15 // pit II: film liquid an amount of 16 MP [I] [J] =% K; . 17 // pit three: the starting point 18 is F [I] [J] [MP [I] [J]] [ 0 ] = . 1 ; . 19 } 20 is } 21 is // the DP 22 is for ( int I = . 1 ; I <= n-; I ++ ) { 23 is for(int j=1;j<=m;j++){ 24 for(int c=0;c<k;c++){ 25 //坑四:取膜 26 int tmp=(c-mp[i][j]+k)%k; 27 f[i][j][c][0]+=(f[i-1][j][tmp][1]%mod+f[i][j-1][tmp][1]%mod)%mod; 28 f[i][j][c][0]%=mod; 29 30 tmp=(c+mp[i][j])%k; 31 f[i][j][c][1]+=(f[i-1][j][tmp][0]%mod+f[i][j-1][tmp][0]%mod)%mod; 32 f[i][j][c][1]%=mod; 33 } 34 sum=(sum+f[i][j][0][1])%mod; 35 } 36 } 37 cout<<sum<<endl; 38 return 0; 39 }
End Sahua