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 ...
随机推荐
- 项目管理工具 Redmine 安装试用手记
原文:项目管理工具 Redmine 安装试用手记 项目管理工具 Redmine 安装试用手记 分类: Redmine2009-06-01 10:12 996人阅读 评论(1) 收藏 举报 项目管理工具 ...
- jquery 产品查看放大镜组件
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 四个漂亮的CSS样式表
1. 单像素边框CSS表格 这是一个非经常常使用的表格样式. 源码: <!-- CSS goes in the document HEAD or added to your external s ...
- 33、Python.Unix和Linux系统管理指南.(美)基弗特
- DataUml Design 课程6-DataUML Design 1.1版本号正式宣布(支持PD数据模型)
从DataUML Design正式宣布到现在两个月,因为最近忙,出版到现在为止1.1版本号.稍后我们将始终坚持以良好DataUML Design软件,我希望程序员有很多支持. 一.1.1新的和改进的版 ...
- 最佳新秀Java(22)——再次了解泛型
仿制药Java SE 1.5新功能.通用自然是参数化类型.即操作数据类型被指定为一个参数.这样的参数类型可以在课堂上使用.创建的接口和方法,他们被称为通用类..泛型方法. Java语言引入泛型的优点是 ...
- winform动态的文字效果
效果图如下
- Event notifications
SQL Server 事件通知(Event notifications) 2013-12-13 17:21 by 听风吹雨, 333 阅读, 3 评论, 收藏, 编辑 一. 背景 SQL Server ...
- 使用 HttpClient 进行连接
对于System.Net.Http的学习(二)——使用 HttpClient 进行连接 对于System.Net.Http的学习(一)——System.Net.Http 简介 使用 HttpCl ...
- 圆形头像以及一些常见需求形状自定义ImageView组件
在实际开发中,我们经常会遇到这样的需求,就是无论图片长啥样,我们都要其显示成圆形.圆形加一个边框.矩形加边框,带圆角的矩形等等,lib和demo下载地址:https://github.com/mapl ...