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 ...
随机推荐
- Unity3D开发必备神器(Visual Studio Tools for Unity)
Unity3D开发必备神器(Visual Studio Tools for Unity) 开发Unity3D程序你用的什么IDE呢? 1.MonoDevelop 2.VS 可能你的回答是这样的,我用的 ...
- 反射导出excel案例
1.代码案例: protected void btnExportExcel_Click(object sender, EventArgs e) { SetSearchValue(); Dictiona ...
- ref引用类型,数组型参数,out输出参数
ref和out的相同点和不同点 共同点:都是引用传递不同点:ref的参数在调用之前一定要赋值,在方法调用的过程中可以不要赋值. out的参数在调用之前可以不赋值,在方法调用的过程中一定要赋值. ...
- 使用POI 导入excel
引言:最近一直在接触excel的问题,网页也有很多关于POI解析excel的资料,我也简单的整理了下,有不对地方的还望及时指正,渴望与大家交流并学习. public int importExcel(F ...
- ModelBinder——ASP.NET MVC Model绑定的核心
ModelBinder——ASP.NET MVC Model绑定的核心 Model的绑定体现在从当前请求提取相应的数据绑定到目标Action方法的参数.通过前面的介绍我们知道Action方法的参数通过 ...
- Plan : 破晓
题记 : 不要因为走的太远而忘记自己为什么而出发. 1. 白书(算法竞赛入门经典)看完(每一句话都要读懂) 2. 每次听完课把当天内容复习完(自习室10点以后复习) 3. 微机实验要提前预习(把实验报 ...
- ORACLE总结系列1--network文件夹里的admin的三个文件信息
sqlnet.ora 作用类似于linux或者其他unix的 nsswitch.conf文件,通过这个文件来决定怎么样找一个连接中出现的连接字符串(connect descriptor) 假如sqln ...
- 一、SOAP简单对象访问协议讲解
一.SOAP简单对象访问协议讲解 今天给大家讲讲SOAP的基本知识.下节给大家演示创建基于SOAP的Web Service. 更多SOA文章请查看我的个人博客. 首先,让我来简单一下入门SOAP所需的 ...
- 设计模式18---设计模式之策略模式(Strategy)(行为型)
1.场景模拟 简单的报价管理系统: 对于普通用户和新用户报全价 对于老客户统一折扣5% 对于大客户统一折扣10% 2.不用模式的解决方案 package demo16.strategy.example ...
- [转]Patching the Mach-o Format the Simple and Easy Way
From:http://secureallthethings.blogspot.jp/2014/08/patching-mach-o-format-simple-and-easy.html I'm r ...