简单搜索 练习一下回溯

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
using namespace std;
int n,k;
int ans;
char s[][];
int usex[],usey[];
bool ok(int x,int y){
if(x<||x>=n||y<||y>=n)
return ;
if(s[x][y]=='.'){
return ;
}
if(usex[x]==||usey[y]==)
return ;
return ;
}
void dfs(int x,int y){
if(y==k){
ans++;
return ;
}
if(x>n){
return ;
}
for(int i=;i<n;i++){
if(ok(x,i)){
usey[i]=;
usex[x]=;
dfs(x+,y+);
usey[i]=;
usex[x]=;
}
}
dfs(x+,y);
}
int main(){
while(~scanf("%d%d",&n,&k),n!=-||k!=-){
ans=;
memset(usey,,sizeof(usey));
memset(usex,,sizeof(usex));
for(int i=;i<n;i++){
scanf("%s",s[i]);
}
dfs(,);
printf("%d\n",ans);
}
return ;
}

最新文章

  1. 细谈Slick(6)- Projection:ProvenShape,强类型的Query结果类型
  2. 用keytool工具生成签名文件与获取摘要信息
  3. 通过JDBK操作数据库
  4. 转载:scala中:: , +:, :+, :::, ++的区别
  5. Mac升级到Yosemite后默认的php版本不支持imagetfftext函数问题解决
  6. OpenCV 学习之路(1)
  7. 每天一个Linux命令
  8. python 内建函数功能函数 abs() coerce() divmod() round() pow()
  9. MSDN在线
  10. POJ-2752 Seek the Name, Seek the Fame(KMP,前缀与后缀相等)
  11. 微软职位内部推荐-Sr SDE-MOD-Beijing
  12. freebsd
  13. PHP - 概述
  14. java.io.IOException: Invalid header signature; read 0xE011BDBFEFBDBFEF, expected 0xE11AB1A1E011CFD0
  15. hexo工具介绍及使用方法
  16. JavaWeb 后端 &lt;十一&gt; 之 DBUtils 框架 (基本使用 结果集 事务处理 对表读取)
  17. SpringBoot集成MongoDB
  18. http://ctf.bugku.com/challenges#%E9%80%86%E5%90%91%E5%85%A5%E9%97%A8:bugku--逆向入门
  19. #8 Python数学方法
  20. Codeforces E - Connected Components?

热门文章

  1. expdp ORA-39213
  2. mysql 远程连接 1045 Access denied for user &#39;root&#39;@&#39;XX.XX.XX.XX&#39; (using password:YES)
  3. stream的Read、Write方法实例
  4. 2014年辛星完全解读Javascript第一节
  5. RedHat和CentOS使用本地yum源配置
  6. OFBiz进阶之HelloWorld(一)创建热部署模块
  7. &lt;一&gt; jQuery 简单介绍
  8. Android开发(一):环境搭建
  9. js实现方法的链式调用
  10. Discuz CDN优化方案