问题描述
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cstring> #include<cstdlib> using namespace std; #define LL long long #define MOD 1000000007 LL dp[55][55][13][13]; int gra[55][55]; int n,m,step; bool inside(int x,int y) { if(x>0&&x<=n&&y>0&&y<=m) return 1; return 0; } void dfs(int x,int y,int st,int maxn) { if(dp[x][y][st][maxn]!=-1) return; dp[x][y][st][maxn]=0; if(!inside(x,y)) return; if(st==1&&x==1&&y==1&&gra[1][1]<maxn) { dp[x][y][st][maxn]=1; return; } if(st==0&&x==1&&y==1) { dp[x][y][st][maxn]=1; return; } if(gra[x][y]<maxn&&st>0) { dfs(x-1,y,st-1,gra[x][y]); dp[x][y][st][maxn]=(dp[x][y][st][maxn]+dp[x-1][y][st-1][gra[x][y]])%MOD; dfs(x,y-1,st-1,gra[x][y]); dp[x][y][st][maxn]=(dp[x][y][st][maxn]+dp[x][y-1][st-1][gra[x][y]])%MOD; } dfs(x-1,y,st,maxn); dp[x][y][st][maxn]=(dp[x][y][st][maxn]+dp[x-1][y][st][maxn])%MOD; dfs(x,y-1,st,maxn); dp[x][y][st][maxn]=(dp[x][y][st][maxn]+dp[x][y-1][st][maxn])%MOD; } int main() { memset(dp,-1,sizeof(dp)); //dp[1][0][1]=dp[0][1][1]=1; scanf("%d%d%d",&n,&m,&step); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&gra[i][j]); dfs(n,m,step,15); cout<<dp[n][m][step][15]<<endl; return 0; }
原文:http://www.cnblogs.com/jasonlixuetao/p/6533199.html