zoj 2100 Seeding 【dfs】
来源:互联网 发布:警惕网络炒汇陷阱 编辑:程序博客网 时间:2024/05/16 14:15
Seeding
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 89 Accepted Submission(s) : 41
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
思路:Tom想给农田播种,为了不伤害机器 ,他不能走有石头的‘S’,但是又不能走已经播过的地,问他能不能把所有的地都播完。
代码:
#include<stdio.h>#include<string.h>char s[10][10];int n,m,sum,t,f;void dfs(int x,int y){if(x>=0&&x<=n-1&&y>=0&&y<=m-1&&s[x][y]=='.'){ sum++;s[x][y]='S';if(sum==n*m-t){f=1;return ;}dfs(x,y+1);dfs(x,y-1);dfs(x-1,y);dfs(x+1,y);sum--;s[x][y]='.';}}int main(){int i,j;while(scanf("%d%d",&n,&m)!=EOF&&n|m){sum=0,t=0;f=0;for(i=0;i<n;i++){scanf("%s",s[i]);}for(i=0;i<n;i++){for(j=0;j<m;j++){if(s[i][j]=='S'){t++;}}}dfs(0,0);if(f)printf("YES\n");elseprintf("NO\n");}return 0;}
0 0
- zoj 2100 Seeding(dfs)
- ZOJ 2100--Seeding【DFS】
- zoj 2100 Seeding 【dfs】
- ZOJ 2100 Seeding(dfs)
- ZOJ 2100 Seeding DFS
- ZOJ 2100 seeding 【DFS】
- ZOJ 2100 Seeding(简单DFS)
- zoj 2100 seeding(dfs)
- zoj 2100 Seeding(DFS水水~)
- ZOJ 题目2100 Seeding(DFS)
- zoj 2100Seeding(dfs+回溯)
- ZOJ 2100 Seeding(深搜)
- zoj 2100 Seeding
- zoj 2100 Seeding
- zoj 2100 Seeding
- ZOJ 2100 Seeding
- zoj 2100Seeding
- zoj 2100 Seeding
- POJ1465 Multiple BFS+同余判重
- 用objective-c开发的第一个mac程序(3)——动态库与静态库的问题
- 黑马程序员——Java 面型对象_封装
- 27 水池数目【dfs】
- solr学习
- zoj 2100 Seeding 【dfs】
- 【Linux】如何用shell编写斐波那契函数
- Linux&C open creat read write lseek 函数用法总结
- openwrt 应用程序之netifd
- fork()和vfork()的区别,signal函数用法,exec()系列函数的用法小结
- linux top 命令详解
- 时间Date的各种获取方式
- SQL server2008 身份认证模式修改密码
- LVM&RAID