POJ 1315 Don't Get Rooked
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 2086 | Accepted: 1325 |
Description
The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of rooks in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways. 
Your task is to write a program that, given a description of a board, calculates the maximum number of rooks that can be placed on the board in a legal configuration.
Input
Output
Sample Input
4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0
Sample Output
5
1
5
2
4
题目大意:在一个有着可以阻碍攻击的墙的棋盘上摆放车,使其相互之间不能攻击,输出能够摆放车的最大数量。
解题方法:用DFS直接暴搜。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; int ans;
char maze[][];
int visited[][];
int n; void DFS(int sum)
{
ans = max(ans, sum);
for (int i = ; i < n; i++)
{
for (int j = ; j < n; j++)
{
bool bflag = true;
for (int k = i; k < n; k++)
{
if (visited[k][j])
{
bflag = false;
break;
}
else
{
if (maze[k][j] == 'X')
{
break;
}
}
}
for (int k = i - ; k >= ; k--)
{
if (visited[k][j])
{
bflag = false;
break;
}
else
{
if (maze[k][j] == 'X')
{
break;
}
}
}
for (int k = j; k < n; k++)
{
if (visited[i][k])
{
bflag = false;
break;
}
else
{
if (maze[i][k] == 'X')
{
break;
}
}
}
for (int k = j - ; k >= ; k--)
{
if (visited[i][k])
{
bflag = false;
break;
}
else
{
if (maze[i][k] == 'X')
{
break;
}
}
}
if (bflag && maze[i][j] != 'X')
{
visited[i][j] = ;
DFS(sum + );
visited[i][j] = ;
}
}
}
} int main()
{
while(cin>>n)
{
if (n == )
{
break;
}
ans = ;
for (int i = ; i < n; i++)
{
cin>>maze[i];
}
memset(visited, , sizeof(visited));
DFS();
printf("%d\n", ans);
}
return ;
}
POJ 1315 Don't Get Rooked的更多相关文章
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
随机推荐
- redmine安装详解
1.Linux:centos6.4(32位)2.Gcc的编译环境.使用make命令编辑.yum install gcc-c++ 3.PCRE PCRE(Perl Compatible Regular ...
- Installing Apache, PHP, and MySQL on Mac OS X
I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each ...
- linux yum安装指定版本mysql
1.下载mysql rpm包 cd /usr/local/src wget https://dev.mysql.com/get/mysql80-community-release-el7-.noarc ...
- CF Gym 100187J Deck Shuffling (dfs判连通)
题意:给你一堆牌,和一些洗牌机,可以改变牌的顺序,问你能不能通过洗牌机把数字为x的牌洗到第一个位置. 题解:反向建边,dfs判断连通性 #include<cstdio> #include& ...
- cv2.Canny 边缘检测
Canny边缘检测 Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测 - 算法能够尽可能多地标识出图像中的实际边缘. 好的定位 - 标识出的边缘要尽可能与实际图像中 ...
- SpringMVC-请求参数的绑定
绑定的机制 表单提交的数据都是k=v格式的 username=haha&password=123 SpringMVC的参数绑定过程是把表单提交的请求参数,作为控制器中方法的参数进行绑定的 要求 ...
- k8s1.13.0二进制部署-Dashboard和coredns(五)
部署UI 下载yaml文件https://github.com/kubernetes/kubernetes [root@k8s-master1 ~]# git clone https://github ...
- python-下拉框处理
在自动化中python对下拉框的处理网上相对实例比较少,其它前辈写的教程中对下拉也仅仅是相对与教程来说的,比如下面: m=driver.find_element_by_id("Shippin ...
- java 第11次作业:你能看懂就说明你理解了——this关键字
this 代表当前对象
- CocoaPods在OS X Yosemite上突然不能用了的解决办法
最近开发的时候发现自己的CocoaPods不能使用了! 根据报的错误上网搜寻answer,于是搜到了解决办法 在 OS X Yosemite 报这样的错: [MT] DVTAssertions: AS ...