hdu1045
#include<iostream>
using namespace std;
int count = 0, n = 0;
//判断该ch[x][y]是否可以放置
bool isOk(char **ch, int x, int y){
int i;
//向上检索
for (i = x - 1; i >=0; --i){
if(ch[i][y]=='0'){
return false;
}
//碰到墙
if(ch[i][y] == 'X'){
break;
}
}
//向左检索
for (i = y - 1; i >=0; --i){
if(ch[x][i]=='0'){
return false;
}
//碰到墙
if(ch[x][i] == 'X'){
break;
}
}
return true;
}
void search(char **ch, int k, int step){
int x, y;
if(k == n * n){//到达最末
//是否大于之前的count
if(step > count){
count = step;
return;
}
}else {
x = k / n;//行数
y = k % n;//列数
if(ch[x][y] == '.' && isOk(ch, x, y)){
ch[x][y] = '0';
search(ch, k+1, step+1);//进入k+1步的搜索
//关键理解下面两句!回溯!
ch[x][y] = '.';//重新赋值为'.',为了下一轮的搜索
search(ch, k+1, step);
}else {
//ch[x][y]不为'.',进入k+1步
search(ch, k+1, step);
}
}
return;
}
int main(){
while(cin>>n && n){
count = 0;
char **ch = new char* [n];
for(int i = 0; i < n; ++i){
ch[i] = new char[n];
}
for(int j = 0; j < n; ++j){
for(int k = 0; k < n; ++k){
cin>>ch[j][k];
}
}
search(ch, 0, 0);
cout<<count<<endl;
}
return 0 ;
}
hdu1045的更多相关文章
- hdu1045 DFS
#include<stdio.h> #include<string.h> int n; int maxx; ][]; ]={,-,,}; ]={,,,-}; ][][];//炮 ...
- hdu1045 Fire Net
在一张地图上建立碉堡(X),要求每行没列不能放两个,除非中间有强挡着.求最多能放多少个碉堡 #include<iostream> #include<cstdio> #inclu ...
- HDU1045 Fire Net(DFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- HDU-1045 Fire Net
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) Me ...
- nyoj587 hdu1045 简单深搜
#include<iostream> #include<cstdio> #include<queue> #include<vector> #includ ...
- hdu1045 Fire Net---二进制枚举子集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意: 给你一幅n*n的图,再给你一些点,这些点的上下左右不能再放其他点,除非有墙('X') ...
- HDU1045(KB10-A 二分图最大匹配)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU1045 Fire Net(DFS枚举||二分图匹配) 2016-07-24 13:23 99人阅读 评论(0) 收藏
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...
- HDU1045:Fire Net(二分图匹配 / DFS)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- 基于C++11线程池
1.包装线程对象 class task : public std::tr1::enable_shared_from_this<task> { public: task():exit_(fa ...
- Python装饰器学习
Python装饰器学习(九步入门) 这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方式. 第一步:最简单的函数,准备附加额外功能 ? 1 2 3 4 5 6 7 8 # -*- ...
- Android项目---LayoutParams
LinearLayout.LayoutParams extends ViewGroup.MarginLayoutParams java.lang.Object ↳ android.view.Vi ...
- 关于TD邮件功能不能发到认证邮箱的解决之法
[原创] 关于TD邮件功能不能发到认证邮箱的解决之法 认证邮箱, 邮件服务器, 用户, 邮件系统 鉴于不少同行询问TD发邮件的问题,今天重新更新一下说明 解决问题的原则如下一.在TD服务器上安装一个邮 ...
- QTP使用技巧
1QTP基本功能的使用 QTP的基本功能包括两大部分:一部分是提供给初级用户使用的关键字视图:另一部分是提供给熟悉VBScript脚本编写的自动化测试工程师使用的专家视图.但是,并没有严格的区分,在实 ...
- ESB 设计
ESB 设计 最近为公司完成了一个 ESB 的设计.下面简要说明一下具体的设计方案. 企业 SOA 整体方案 在前一篇<SOA.ESB.NServiceBus.云计算 总结>中说到,SOA ...
- JS定时跳转URL并输出剩余秒数
1. [代码][JavaScript]代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <scrip ...
- MVC应用程序实现文件库(FlexPaper)
MVC应用程序实现文件库(FlexPaper) 很久之前Insus.NET在实现了<FlexPaper实现文档在线浏览>http://www.cnblogs.com/insus/archi ...
- SugarSync的API总结
SugarSync API App支持SugarSync网盘的前提: 1.AccessKeyID:xxx 2.Private Access Key:xxx 3.AppID:xxx 详细的API总结如下 ...
- 类图class的关联关系(聚合、组合)
类图class的关联关系(聚合.组合) 关联的概念 关联用来表示两个或多个类的对象之间的结构关系,它在代码中表现为一个类以属性的形式包含对另一个类的一个或多个对象的应用. 程序演示:关联关系(code ...