标签:dfs
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
3948
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int map[200][200]; int f[200][200]; int n,m; int dfs(int x,int y) { int s=0; if(x==n&&y==m)return 1; if(f[x][y]>=0)return f[x][y]; int as=map[x][y]; for(int i=x;i<=x+as;i++) for(int j=y;j<=y+as;j++) { if(((i-x)+(j-y)<=as)&&(i<=n)&&(j<=m)&&(i+j)!=x+y) { s+=dfs(i,j); s%=10000; } } f[x][y]=s; return s; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&map[i][j]); memset(f,-1,sizeof(f)); int ans=dfs(1,1); printf("%d\n",ans); } return 0; }
How many ways(dfs+记忆化搜索),布布扣,bubuko.com
标签:dfs
原文地址:http://blog.csdn.net/zhangweiacm/article/details/38682545