标签:
Description
Input
Output
Sample Input
1 6 6 4 5 6 6 4 3 2 2 3 1 7 2 1 1 4 6 2 7 5 8 4 3 9 5 7 6 6 2 1 5 3 1 1 3 7 2
Sample Output
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int maxn=105; const int mod=10000; int a[maxn][maxn]; int dp[maxn][maxn]; int Next[4][2]={0,1,1,0,0,-1,-1,0}; int n,m; int dfs(int x,int y){ if(dp[x][y]>=0) return dp[x][y]; dp[x][y]=0; for(int i=0;i<=a[x][y];i++){ for(int j=0;j<=a[x][y]-i;j++){ if((i+x)>=0&&(i+x)<n&&(j+y)>=0&&(j+y)<m){ dp[x][y]=(dp[x][y]+dfs(x+i,y+j))%mod; } } } return dp[x][y]; } int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ scanf("%d",&a[i][j]); } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ dp[i][j]=-1; } } dp[n-1][m-1]=1; printf("%d\n",dfs(0,0)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4998671.html