Obviously not less than \ (n \) this thing we do is not very good, considering the positive anti difficult to determine the number of paths less than \ (n \) , then take \ (C_ {n + m} ^ m \) a Less like
Thus state \ (dp [i] [j ] [k] \) represents the \ ((i, j) \ ) This product is accumulated lattice \ (K \) of the number of paths, the transfer apparently
However, a look that could not pass the level
So we do not exist until now is how much of the product, we save this change can take much of the grid down the number of
Transfer, we directly go except a weight value of grid like, obviously the number of states does not exceed \ (2 \ sqrt {n} \)
Code
#include<cstdio>
#include<cstring>
#define re register
inline int read() {
char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int mod=1e9+7;
const int maxn=301;
int r,c,n,m,a[maxn][maxn];
int f[maxn][maxn],dp[2][maxn][2500],id[1000005],w[2500];
inline void add(int a,int b,int c,int x,int y,int z) {
dp[a][b][c]=(dp[a][b][c]+dp[x][y][z])%mod;
}
int main() {
r=read(),c=read(),n=read()-1;
f[1][0]=1;
for(re int i=1;i<=r;i++)
for(re int j=1;j<=c;j++) f[i][j]=(f[i-1][j]+f[i][j-1])%mod;
for(re int l=1,r;l<=n;l=r+1)
r=n/(n/l),w[++m]=n/l,id[w[m]]=m;
for(re int i=1;i<=r;i++)
for(re int j=1;j<=c;j++) a[i][j]=read();
dp[0][1][id[n/a[1][1]]]=1;
int o=0;
for(re int i=1;i<=r;i++,o^=1) {
memset(dp[o^1],0,sizeof(dp[o^1]));
for(re int j=1;j<=c;j++)
for(re int k=1;k<=m;k++) {
if(!dp[o][j][k]) continue;
if(i<r&&w[k]/a[i+1][j]>0)
add(o^1,j,id[w[k]/a[i+1][j]],o,j,k);
if(j<c&&w[k]/a[i][j+1]>0)
add(o,j+1,id[w[k]/a[i][j+1]],o,j,k);
}
}
int ans=0;
for(re int k=1;k<=m;k++) ans=(ans+dp[o^1][c][k])%mod;
printf("%d\n",(f[r][c]-ans+mod)%mod);
return 0;
}