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 ...
 
随机推荐
- Integer的一个小问题
			
看面试题的时候看到这道题: public class Demo { public static void main(String[] args) { Integer i1 = 128; Integer ...
 - Erlang程序设计(第2版)读书笔记(一)
			
正如<代码的未来>中所说,为了充分利用多核,并发变成将成为未来发展的趋势,对于并发编程的支持,Erlang确实是不二之选,Erlang在国内仍然较为小众,经典书籍相对也要少很多,最终选择了 ...
 - Uva 10635 Prince and Princess (LCS变形LIS)
			
直接LCS是时间复杂度是O(p*q)的,但是序列元素各不相同,只要把其中一个序列映射成有序的, 另外一个序列再做相同的映射,没有的直接删掉,就变成了求另一个序列LIS. #include<bit ...
 - 如何下载js类库
			
https://bower.io/ 这个已经淘汰 https://learn.jquery.com/jquery-ui/environments/bower/ Web sites are made ...
 - 《毛毛虫组》【Alpha】Scrum meeting 3
			
第二天 日期:2019/6/16 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: 货物入库管理模块设计: (1)对数据库表--tb_InStore进行修改并完善: (2)学习SQL Se ...
 - redis入门指南书中概要
			
一.简介 1.redis是一个开源的.高性能的.基于键值对的缓存和存储系统,通过提供多种键值数据类型适应不同场景下的缓存和存储需求,同时redis高级功能能胜任消息队列.任务队列等不同角色. 2.内存 ...
 - NOIP模拟赛 虫洞
			
[题目描述] John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N (从1. ...
 - PHP实现同array_column一样的功能
			
不用PHP自带的array_column函数实现同样的功能 <?php /** * Created by PhpStorm. * User: 123456 * Date: 2018/9/25 * ...
 - C++简易酒店管理系统,实现(查询、入住、退房、楼层选择、退出)功能
			
#include <iostream> #include <string.h> #include <stdlib.h> void enter(); void che ...
 - Python3 pymsyql 连接读取数据
			
import pymysql conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='root', db='t ...