POJ 1321 棋盘问题 DFS搜索
2024-10-14 02:00:35
简单搜索 练习一下回溯
#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 ;
}
最新文章
- 细谈Slick(6)- Projection:ProvenShape,强类型的Query结果类型
- 用keytool工具生成签名文件与获取摘要信息
- 通过JDBK操作数据库
- 转载:scala中:: , +:, :+, :::, ++的区别
- Mac升级到Yosemite后默认的php版本不支持imagetfftext函数问题解决
- OpenCV 学习之路(1)
- 每天一个Linux命令
- python 内建函数功能函数 abs() coerce() divmod() round() pow()
- MSDN在线
- POJ-2752 Seek the Name, Seek the Fame(KMP,前缀与后缀相等)
- 微软职位内部推荐-Sr SDE-MOD-Beijing
- freebsd
- PHP - 概述
- java.io.IOException: Invalid header signature; read 0xE011BDBFEFBDBFEF, expected 0xE11AB1A1E011CFD0
- hexo工具介绍及使用方法
- JavaWeb 后端 <;十一>; 之 DBUtils 框架 (基本使用 结果集 事务处理 对表读取)
- SpringBoot集成MongoDB
- http://ctf.bugku.com/challenges#%E9%80%86%E5%90%91%E5%85%A5%E9%97%A8:bugku--逆向入门
- #8 Python数学方法
- Codeforces E - Connected Components?
热门文章
- expdp ORA-39213
- mysql 远程连接 1045 Access denied for user &#39;root&#39;@&#39;XX.XX.XX.XX&#39; (using password:YES)
- stream的Read、Write方法实例
- 2014年辛星完全解读Javascript第一节
- RedHat和CentOS使用本地yum源配置
- OFBiz进阶之HelloWorld(一)创建热部署模块
- <;一>; jQuery 简单介绍
- Android开发(一):环境搭建
- js实现方法的链式调用
- Discuz CDN优化方案