Cannon

Time Limit: 1000ms
Memory Limit: 65535KB

This problem will be judged on HDU. Original ID: 4499
64-bit integer IO format: %I64d      Java class name: Main

 
 
In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move horizontally or vertically along the chess grid. At each move, it can either simply move to another empty cell in the same line without any other chessman along the route or perform an eat action. The eat action, however, is the main concern in this problem. 
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.

 

Input

There are multiple test cases. 
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.

 

Output

There is only one line for each test case, containing the maximum number of cannons.

 

Sample Input

4 4 2
1 1 1 2
5 5 8
0 0 1 0 1 1 2 0 2 3 3 1 3 2 4 0

Sample Output

8
9

Source

 
解题:搜索。攻击条件就是一行或一列有三棋,最前和最后的棋是炮就不行,炮棋棋可以,炮棋炮 炮炮炮 不行。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
int n,m,k,ans;
int mp[][];
void dfs(int cur,int has){
int x = cur/m;
int y = cur%m;
if(has > ans) ans = has;
if(cur == n*m) return;
if(mp[x][y]) {dfs(cur+,has);return;}
dfs(cur+,has);
int i,cnt = ;
for(i = x-; i >= ; i--){
if(mp[i][y]) cnt++;
if(cnt == ) break;
}
if(cnt == && mp[i][y] == ) return;
cnt = ;
for(i = y-; i >= ; i--){
if(mp[x][i]) cnt++;
if(cnt == ) break;
}
if(cnt == && mp[x][i] == ) return;
mp[x][y] = ;
dfs(cur+,has+);
mp[x][y] = ;
}
int main() {
int i,j,x,y;
while(~scanf("%d %d %d",&n,&m,&k)){
memset(mp,,sizeof(mp));
for(i = ; i < k; i++){
scanf("%d %d",&x,&y);
mp[x][y] = ;
}
ans = ;
dfs(,);
printf("%d\n",ans);
}
return ;
}

BNUOJ 33898 Cannon的更多相关文章

  1. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  2. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  3. Parallel Computing–Cannon算法 (MPI 实现)

    原理不解释,直接上代码 代码中被注释的源程序可用于打印中间结果,检查运算是否正确. #include "mpi.h" #include <math.h> #includ ...

  4. bnuoj 24251 Counting Pair

    一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...

  5. bnuoj 44359 快来买肉松饼

    http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms     Case Time Lim ...

  6. 炮(cannon)

    炮(cannon)[题目描述] 众所周知,双炮叠叠将是中国象棋中很厉害的一招必杀技.炮吃子时必须隔一个棋子跳吃,即俗称“炮打隔子”. 炮跟炮显然不能在一起打起来,于是rly一天借来了许多许多的炮在棋盘 ...

  7. BNUOJ 1006 Primary Arithmetic

    Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...

  8. bnuoj 34985 Elegant String DP+矩阵快速幂

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...

  9. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

随机推荐

  1. UVaLive 6833 Miscalculation (表达式计算)

    题意:给定一个表达式,只有+*,然后问你按照法则运算和从左到右计算结果有什么不同. 析:没什么可说的,直接算两次就好. 代码如下: #pragma comment(linker, "/STA ...

  2. bzoj 1724: [Usaco2006 Nov]Fence Repair 切割木板【堆】

    如果反着看,看成合并木板,就和合并果子一样了,把若干块放进一个小根堆,然后每次取出两个合并,把合并结果加进答案和堆里 代码里小根堆用优先队列实现(懒 #include<iostream> ...

  3. 清北考前刷题day6早安

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...

  4. wamp集成环境下帝国备份出错

    我在本地wamp环境下面使用帝国备份王时,报错信息如下: Parse error: syntaxerror, unexpected $end in D:wampwwwhuifuclassfunctio ...

  5. uiautomatorviewer详解

    一,uiautomatorviewer是什么? Android 4.1发布的,uiautomator是用来做UI测试的.也就是普通的手工测试,点击每个控件元素 看看输出的结果是否符合预期.比如 登陆界 ...

  6. Java学习笔记-eclipse配置

    一.配置Java环境变量 JAVA_HOME:D:\Program Files\Java\jdk1.7.0_76 CLASSPATH:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HO ...

  7. VC++常见错误原因解析--error LNK2019: 无法解析的外部符号 "public: void __thiscall

    根据个人遇到这个错误时的记录,原因可以分为一下几种: 原因一: 只是在.h里面声明了某个方法, 没有在cpp里面实现 . 具体讲,有时候在头文件中声明了需要的方法,确实忘记了在源文件中实现: 有时候在 ...

  8. P2P 网络核心技术:Gossip 协议

    背景 Gossip protocol 也叫 Epidemic Protocol (流行病协议),实际上它还有很多别名,比如:“流言算法”.“疫情传播算法”等. 这个协议的作用就像其名字表示的意思一样, ...

  9. [ CodeForces 1065 B ] Vasya and Isolated Vertices

    \(\\\) \(Description\) 求一个\(N\)个点\(M\)条边的无向图,点度为 \(0\) 的点最多和最少的数量. \(N\le 10^5,M\le \frac {N\times ( ...

  10. QQ应用前景与范围文档

    QQ软件 前景与范围文档       当前版本: 版本1 作   者: 李飞 完成日期: 2013年11月3日 1.  业务需求 1.1 应用背景 20世纪后期网络的应用和21世纪的飞速发展,网络已经 ...