走迷宫(dfs)
2013-10-12 16:36
253 查看
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2449
View Code
#include<stdio.h> #include<string.h> const int N=520; int vis ,map ; int n,m,cnt; void dfs(int x,int y) { if (x==n&&y==m) { cnt++; return ; } if (x-1>=1&&map[x-1][y]==0&&!vis[x-1][y]) { vis[x][y] = 1; dfs(x-1,y); vis[x][y] = 0; } if (x+1<=n&&map[x+1][y]==0&&!vis[x+1][y]) { vis[x][y] = 1; dfs(x+1,y); vis[x][y] = 0; } if (y-1>=1&&map[x][y-1]==0&&!vis[x][y-1]) { vis[x][y] = 1; dfs(x,y-1); vis[x][y] = 0; } if (y+1<=m&&map[x][y+1]==0&&!vis[x][y+1]) { vis[x][y] = 1; dfs(x,y+1); vis[x][y] = 0; } } int main() { int t; scanf("%d",&t); while(t--) { cnt = 0; scanf("%d%d",&n,&m); memset(vis,0,sizeof(vis)); for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++ ) { scanf("%d",&map[i][j]); } } vis[1][1] = 1; dfs(1,1); printf("%d\n",cnt); } return 0; }
View Code
相关文章推荐
- 【Cocos2d游戏开发之二】CCScene场景切换的特效
- PHP JSON_DECODE/JSON_ENCODE中文内容为NULL或乱码
- Jquery ajax方法解析返回的json数据
- x2检验(chi-square test)或称卡方检验
- ubuntu中vsftpd虚拟用户实现不同用户不同权限
- windows程序员进阶系列:《软件调试》之堆 的基本概念和分类
- 网络爬虫 学习2
- asp.net长文章插入指定分页符进行分页
- STL Composite Key Map
- c语言time与clock区别
- 编译期检查class是否有继承关系
- Mac OS X 的文件系统
- openssh 安装配置及使用
- CSS感言1 初级。
- File类的基本创建、删除与获取文件信息
- linux shell touch 命令
- mysql常用语句
- 平面最近点对
- SHH入门:Spring框架简介
- OCP-1Z0-052-V8.02-76题