Seeding zoj2100 【DFS】
来源:互联网 发布:修复痘印 知乎 编辑:程序博客网 时间:2024/04/29 21:27
Tom has a seeding-machine. At the beginning, the machine lies in the top left corner of the field. After the machine finishes one square, Tom drives it into an adjacent square, and continues seeding. In order to protect the machine, Tom will not drive it into a square that contains stones. It is not allowed to drive the machine into a square that been seeded before, either.
Tom wants to seed all the squares that do not contain stones. Is it possible?
Input
The first line of each test case contains two integers n and m that denote the size of the field. (1 < n, m < 7) The next n lines give the field, each of which contains m characters. 'S' is a square with stones, and '.' is a square without stones.
Input is terminated with two 0's. This case is not to be processed.
Output
For each test case, print "YES" if Tom can make it, or "NO" otherwise.
Sample Input
4 4
.S..
.S..
....
....
4 4
....
...S
....
...S
0 0
Sample Output
YES
NO
#include<stdio.h>int m,n;char vis[10][10];bool flag;int dx[]={0,1,-1,0};int dy[]={1,0,0,-1};void DFS(int x,int y,int num){if(num==n*m){flag=1;}if(vis[x][y]=='S'||x>m||x<1||y<0||y>n-1) return ;for(int i=0;i<4;++i){int fx=x+dx[i];int fy=y+dy[i];if(vis[x][y]='.'){vis[x][y]='S';//走过后要标记 DFS(fx,fy,num+1);vis[x][y]='.';//回溯时要还原 }}}int main(){while(~scanf("%d%d",&m,&n),m|n){int num=0;flag=0;for(int i=1;i<=m;++i){scanf("%s",vis[i]);}for(int i=1;i<=m;++i){for(int j=0;j<n;++j){if(vis[i][j]=='S')num++;}}DFS(1,0,num);if(flag) printf("YES\n");else printf("NO\n");}return 0;}
- Seeding zoj2100 【DFS】
- zoj2100 Seeding (DFS递归+回溯)
- ZOJ2100-Seeding(dfs基础题)
- zoj2100 Seeding
- Seeding--zoj2100
- zoj2100-Seeding
- zoj2100(DFS)
- Seeding【dfs】
- Seeding 【dfs】
- Seeding 2900 【DFS】
- zoj 2100 Seeding(dfs)
- ZOJ 2100--Seeding【DFS】
- HDOJ Seeding (DFS)
- 2100 Seeding【dfs】
- zoj 2100 Seeding 【dfs】
- ZOJ 2100 Seeding(dfs)
- ZOJ 2100 Seeding DFS
- ZOJ 2100 seeding 【DFS】
- HDFS之Node角色
- Android控件自定义属性的使用
- GPL和AGPLv3的区别
- IE 6/7 bug --- float:right
- poj3301Texas Trip三分旋转角度
- Seeding zoj2100 【DFS】
- odoo conf
- doxygen 使用简介(C,C++为代码作注释)
- Java抽象类的理解
- 被我们误读的诗句《静夜思》
- 移动测试人员的未来:测试开发技术的融合
- Pinterest开源图片下载和缓存框架--PINRemoteImage
- iOS中几种数据持久化方案-1
- CDataExchange()