递归 Seeding
来源:互联网 发布:少见的姓氏 知乎 编辑:程序博客网 时间:2024/06/05 05:50
Seeding
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 109 Accepted Submission(s) : 56
Problem Description
It is spring time and farmers have to plant seeds in the field. Tom has a nice field, which is a rectangle with n * m squares. There are big stones in some of the squares. 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
Source
Zhejiang University Local Contest 2004
#include<stdio.h>#include<string.h>int c[10][10];int a,b,tem,max,flag;void fun(int x,int y){if(flag){return ;}if(x<1||x>a||y<1||y>b)return ;if(c[x][y]=='S')return ;c[x][y]='S';tem++;if(tem==a*b){flag=1;return ;}fun(x,y+1);fun(x,y-1);fun(x-1,y);fun(x+1,y);tem--;c[x][y]='.';}int main(){int i,j;while(scanf("%d%d",&a,&b),a|b){tem=0;max=0;flag=0;for(i=1;i<=a;i++){getchar();for(j=1;j<=b;j++){scanf("%c",&c[i][j]);if(c[i][j]=='S')tem++;}}fun(1,1);if(flag)printf("YES\n");else printf("NO\n");}return 0;}
0 0
- 递归 Seeding
- zoj2100 Seeding (DFS递归+回溯)
- Seeding
- Seeding
- Seeding
- Seeding
- Seeding zoj
- ZOJ-Seeding
- Seeding 2100
- zhejiang Seeding
- Seeding【dfs】
- Seeding 【dfs】
- zoj2100 Seeding
- Seeding--zoj2100
- zoj2100-Seeding
- Seeding 2900 【DFS】
- ZOJ 2100 Seeding(深搜)
- zoj 2100 Seeding
- 南邮 OJ 1124 Hotel
- mysql优化建议
- 针对QTP连接oracle数据库问题总结
- 未能找到类型或命名空间名称“SYNCTMS”(是否缺少 using 指令或程序集引用?)
- struts 工作流程
- 递归 Seeding
- JavaScript的加载和运行
- 南邮 OJ 1125 Substring
- 用静态工厂方法代替构造器
- android 消息提示框点击“确定”按钮后,不能及时关闭提示框的解决方案
- 2015年8月3日--oracle
- 配置IIS7运行CGI脚本创建动态网页
- WPF MVVM初体验
- importtsv工具使用笔记