Seeding


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

主要就是深搜!

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,ds;
char map[][];
int move[][]={,,,-,,,-,};
int visit[][],cot,flag;
void dfs(int x,int y)
{
int next_x,next_y,i;
if(cot==ds)//如果已经找完了所有的点就跳出
{
flag=;//设置一个开关
return;
}
for(i=;i<;i++)
{
next_x=x+move[i][];
next_y=y+move[i][];//往四个方向移动
if(next_x>=&&next_x<n&&next_y>=&&next_y<m)//在图的范围内
{
if(!visit[next_x][next_y]&&map[next_x][next_y]!='S') //没被访问过,这个点还不能是S
{
cot++;//访问一次就加一次
visit[next_x][next_y]=;//标记为走过
dfs(next_x,next_y);//进入下一层
visit[next_x][next_y]=;//取消标记
cot--;//跳出一次就减一次
}
}
}
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m),n||m)
{
getchar();
cot=;
ds=;
flag=;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
visit[i][j]=;
scanf("%c",&map[i][j]);
if(map[i][j]=='.')
ds++;//记录点的个数
}
getchar();
}
visit[][]=;//访问过就标记为1
cot++;//先加一次
dfs(,);//从0,0点开始访问
//printf("%d\n",ds);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}

最新文章

  1. video/audio在ios/android上播放兼容
  2. javascript快速入门
  3. 连接到kali linux服务器上的MySQL服务器错误
  4. html5 canvas画图之图形随拖动而复制(有操作指示)
  5. web项目总结
  6. SQL注入测试平台 SQLol -4.UPDATE注入测试
  7. 【转】 ip段/数字,如192.168.0.1/24是什么意思?
  8. POJ 1062 昂贵的聘礼(Dijkstra)
  9. web前端开发分享-css,js入门篇(转)
  10. sass学习(1)——了解sass
  11. POJ 3083 Children of the Candy Corn 解题报告
  12. 图片延迟加载插件jquery.lazyload.js的使用方法
  13. 窗体前端显示(ShowWindowAsync有许多优点)
  14. JavaEE Tutorials (22) - 事务
  15. ThinkPHP框架配置自定义的模板变量(十)
  16. htc one x刷机记录
  17. 对Jquery中的ajax再封装,简化操作
  18. oracle数据库修改连接数
  19. mac os X下的updatedb
  20. shell脚本逐个杀死k8s中某个应用的pod

热门文章

  1. 基于cygwin构建u-boot(二)gcc的C语言标准版本号(-std=)
  2. 利用fiddler录制脚本
  3. 从一道面试题谈linux下fork的运行机制
  4. USB系列之六:基于DOSUSB的简单U盘驱动程序
  5. 分布式文件系统MooseFS安装步骤
  6. 在Qt中怎样显示ASCII码大于127的字符
  7. jquery判断元素是否隐藏的多种方法
  8. bzoj1643 [Usaco2007 Oct]Bessie&#39;s Secret Pasture 贝茜的秘密草坪
  9. hdu 1987-How many ways(dp)
  10. mongoDB windows reinstall add auth