Dp began to think that a four-dimensional state have a good job, and then to write a thief nausea
Then change the search, four types of branch want a good, but the complexity is not right?
After giving up, looking solution to a problem, Lv, really two together, memory search.
Well, indeed you, the Blue Bridge Cup, so like violence algorithm!
PS:
Searching for a state, the return value may be 0, so the array assigned to the initial value of -1
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 const int MOD=1e9+7; 6 int n,m,k; 7 int v[55][55]; 8 int f[55][55][15][15]; 9 int dfs(int x,int y,int num,int max){ 10 if(f[x][y][num][max+1]!=-1)return f[x][y][num][max+1]; 11 if(x==n&&y==m)return f[x][y][num][max+1]=(num==k||(num==k-1&&max<v[x][y])); 12 int ans=0; 13 if(x+1<=n){ 14 if(max<v[x][y])ans=(ans+dfs(x+1,y,num+1,v[x][y]))%MOD; 15 ans=(ans+dfs(x+1,y,num,max))%MOD; 16 } 17 if(y+1<=m){ 18 if(max<v[x][y])ans=(ans+dfs(x,y+1,num+1,v[x][y]))%MOD; 19 ans=(ans+dfs(x,y+1,num,max))%MOD; 20 } 21 return f[x][y][num][max+1]=ans; 22 } 23 int main() { 24 cin>>n>>m>>k; 25 for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>v[i][j]; 26 memset(f,-1,sizeof(f));dfs(1,1,0,-1); 27 cout<<f[1][1][0][0]<<endl; 28 return 0; 29 }