#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
vector<vector<vector<int> > > dp;
int r,c,d;
int rec(int i,int j,int right,int down){
if(i==r||j==c||right>d||down>d||a[i][j]==0)return 0;
if(right==0){
if(dp[i][j][down]!=-1)return dp[i][j][down];
return dp[i][j][down]=(rec(i+1,j,0,down+1)%20011+rec(i,j+1,right+1,0)%20011)%20011;
}
if(down==0){
if(dp[i][j][d+right]!=-1)return dp[i][j][d+right];
return dp[i][j][d+right]=(rec(i+1,j,0,down+1)%20011+rec(i,j+1,right+1,0)%20011)%20011;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cin>>r>>c>>d;
a.assign(r,vector<int>(c));
dp.assign(r,vector<vector<int> >(c,vector<int> (2*d+1,-1)));
dp[r-1][c-1]=vector<int> (2*d+2,1);
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>a[i][j];
cout<<rec(0,0,0,0);
}
Comments
Post a Comment