HDU 4499 Cannon (搜索)
Cannon
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 21 Accepted Submission(s): 14
An eat action, for example, Cannon A eating chessman B, requires two conditions:
1、A and B is in either the same row or the same column in the chess grid.
2、There is exactly one chessman between A and B.
Here comes the problem.
Given an N x M chess grid, with some existing chessmen on it, you need put maximum cannon pieces into the grid, satisfying that any two cannons are not able to eat each other. It is worth nothing that we only account the cannon pieces you put in the grid, and no two pieces shares the same cell.
In each test case, there are three positive integers N, M and Q (1<= N, M<=5, 0<=Q <= N x M) in the first line, indicating the row number, column number of the grid, and the number of the existing chessmen.
In the second line, there are Q pairs of integers. Each pair of integers X, Y indicates the row index and the column index of the piece. Row indexes are numbered from 0 to N-1, and column indexes are numbered from 0 to M-1. It guarantees no pieces share the same cell.
1 1 1 2
5 5 8
0 0 1 0 1 1 2 0 2 3 3 1 3 2 4 0
9
数据范围很小,明显是搜索。
主要剪枝,就是不要和前面的冲突了、
/* ***********************************************
Author :kuangbin
Created Time :2013/8/24 14:38:00
File Name :F:\2013ACM练习\比赛练习\2013通化邀请赛\1007.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int n,m;
int g[][];
int ans ; void dfs(int x,int y,int cnt)
{
if(x >= n)
{
ans = max(ans,cnt);
return;
}
if(y >= m)
{
dfs(x+,,cnt);
return;
}
if(g[x][y] == )
{
dfs(x,y+,cnt);
return;
}
dfs(x,y+,cnt);
bool flag = true;
int t;
for(t = x-;t >= ;t--)
if(g[t][y])
{
break;
}
for(int i = t-;i >= ;i--)
if(g[i][y])
{
if(g[i][y]==)flag = false;
break;
}
if(!flag)return;
for(t = y-;t >= ;t--)
if(g[x][t])
break;
for(int j = t-;j >= ;j--)
if(g[x][j])
{
if(g[x][j] == )flag = false;
break;
}
if(!flag)return;
g[x][y] = ;
dfs(x,y+,cnt+);
g[x][y] = ;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int Q;
int u,v;
while(scanf("%d%d%d",&n,&m,&Q) == )
{
memset(g,,sizeof(g));
while(Q--)
{
scanf("%d%d",&u,&v);
g[u][v] = ;
}
ans = ;
dfs(,,);
printf("%d\n",ans);
}
return ;
}
HDU 4499 Cannon (搜索)的更多相关文章
- HDU 4499.Cannon 搜索
Cannon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
- hdu 4499 Cannon(暴力)
题目链接:hdu 4499 Cannon 题目大意:给出一个n*m的棋盘,上面已经存在了k个棋子,给出棋子的位置,然后求能够在这种棋盘上放多少个炮,要求后放置上去的炮相互之间不能攻击. 解题思路:枚举 ...
- HDU 4499 Cannon (暴力搜索)
题意:在n*m的方格里有t个棋子,问最多能放多少个炮且每一个炮不能互相攻击(炮吃炮) 炮吃炮:在同一行或同一列且中间有一颗棋子. #include <stdio.h> #include & ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
- HDU 4499 Cannon (暴力求解)
题意:给定一个n*m个棋盘,放上一些棋子,问你最多能放几个炮(中国象棋中的炮). 析:其实很简单,因为棋盘才是5*5最大,那么直接暴力就行,可以看成一行,很水,时间很短,才62ms. 代码如下: #i ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
- hdu 5468(莫比乌斯+搜索)
hdu 5468 Puzzled Elena /*快速通道*/ Sample Input 5 1 2 1 3 2 4 2 5 6 2 3 4 5 Sample Output Case #1: ...
- HDU 1045 (DFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...
- HDU 1180 (BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1180 题目大意:迷宫中有一堆楼梯,楼梯横竖变化.这些楼梯在奇数时间会变成相反状态,通过楼梯会顺便到达 ...
随机推荐
- 根据经纬度坐标计算距离-python
一.两个坐标之间距离计算 参考链接: python实现 1.Python 根据地址获取经纬度及求距离 2.python利用地图两个点的经纬度计算两点间距离 LBS 球面距离公式 美团app筛选“离我最 ...
- .Net程序集强签名详解
强签名: 1. 可以将强签名的dll注册到GAC,不同的应用程序可以共享同一dll. 2. 强签名的库,或者应用程序只能引用强签名的dll,不能引用未强签名的dll,但是未强签名的dll可以引用强签名 ...
- 使用Docker快速搭建sftp服务
一.安装docker环境 参见 http://www.cnblogs.com/rslai/p/8403350.html 二.从Docker Hub查找sftp镜像 docker search sftp ...
- eclipse导入/导出项目要注意三个地方
这个三个地方的jdk必须保持一致,不报错
- 如何阻止点击scrollviewer里面的单位内容时,自动滚动
<Style TargetType="{x:Type ListBoxItem}"> <Setter Property="FocusVisualStyle ...
- C++ 实现memcpy和strcpy
/** * @Method: Memcpy * @Access: public * @Return: void * * @Param : dst - 目的起始地址 * @Param : src - 源 ...
- c语言循环链表的问题
今天,老师说了一道题,大意是,有一群小朋友10个人,但是老师只有一个苹果,只能给一个小朋友,于是老师就决定让小朋友们做成一圈,从第一个小朋友开始,每隔一个小朋友就没有机会得到苹果,最后剩下的一个人可以 ...
- 【转】Android开启网络调试的方法
方法是偶然看到的: Android 终端adbd服务需要开启5555号端口来建立于adb的连接,如果未开启5555端口,则不能通过网络调试 查看是否可以网络调试: # netstat Android ...
- 【ARC066】F - Contest with Drinks Hard
题解 我写的斜率维护,放弃了我最擅长的叉积维护,然后发现叉积维护也不会爆long long哦-- 一写斜率维护我的代码就会莫名变长而且难写--行吧 我们看这题 推了推式子,发现这是个斜率的式子,但是斜 ...
- jquery实现checkbox的单选和全选
一.思路 全选:判断“全选”checkbox的状态,如果选中则把tbody下所有的checkbox选中,反之 单选:主要是判断有没有全选,如果不是选中状态就把全选的checkbox状态设置为false ...