BNUOJ 33898 Cannon
Cannon
This problem will be judged on HDU. Original ID: 4499
64-bit integer IO format: %I64d Java class name: Main
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
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
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的更多相关文章
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- Parallel Computing–Cannon算法 (MPI 实现)
原理不解释,直接上代码 代码中被注释的源程序可用于打印中间结果,检查运算是否正确. #include "mpi.h" #include <math.h> #includ ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- bnuoj 44359 快来买肉松饼
http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms Case Time Lim ...
- 炮(cannon)
炮(cannon)[题目描述] 众所周知,双炮叠叠将是中国象棋中很厉害的一招必杀技.炮吃子时必须隔一个棋子跳吃,即俗称“炮打隔子”. 炮跟炮显然不能在一起打起来,于是rly一天借来了许多许多的炮在棋盘 ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- 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 ...
- hdu 4499 Cannon dfs
Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...
随机推荐
- bzoj 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课【spfa】
洛谷的数据毒啊 把(i,j,k)作为一个点spfa,表示点(i,j)朝向k方向,然后向四个方向转移即可 #include<iostream> #include<cstdio> ...
- TestNG设置用例循环执行
曾经做过一需求,需要单个集成测试用例循环执行N次,或许你会说for循环就可以了,这当然是可以的.那有没有逼格更高点的方法,当然也是有的.下面我们就说下使用TestNG注解功能实现用例的循环执行. 1. ...
- 转载使用 ContentObsever 拦截短信,获取短信内容
在一些应用上,比如手机银行,QQ,微信等,很多时候我们都需要通过发送验证码到手机上,然后把验证码填上去,然后才能成功地继续去做下面一步事情. 而如果每次我们都要离开当前界面,然后去查收短信,记住验证码 ...
- Visual Studio 生成项目时脚本执行
项目属性 - 生成事件 项目生成前:预先生成事件命令行: 项目生成后:后期生成事件命令行:例:copy $(ProjectDir)Reference\sms_cfg.ini $(TargetDir) ...
- log4j2异步日志解读(一)AsyncAppender
log4j.logback.log4j2 历史和关系,我们就在这里不展开讲了.直接上干货,log4j2突出于其他日志的优势,异步日志实现. 看一个东西,首先看官网文档 ,因为前面文章已经讲解了disr ...
- 【转】Java实现将文件或者文件夹压缩成zip
转自:https://www.cnblogs.com/zeng1994/p/7862288.html package com.guo.utils; import java.io.*; import j ...
- 利用freemarker导出页面格式复杂的excel
刚开始大家可能会利用poi生成简单的excel,但是遇到需要生成复杂的excel,poi导出excel就比较困难,这时候可以利用freemarker来渲染实现实现生成复杂的excel, 首先,将exc ...
- 百度AI车牌识别测试
测试背景 百度已发布诸多AI应用,其中包含车牌识别,免费使用量是200次/日.付费的话,按月调用次数在20万次到50万次之间,每日10000次,月费用为0.0035*300000=1050元. 详见: ...
- 一次“MySQL server has gone away”故障及其解决
1,问题现象 某次测试发现,程序失去响应.由于程序集成了EurekaLog组件,弹出了错误框.查看其给出的Call Stack信息,发现没有发生线程死锁(DeadLock=0;),问题在于 Wait ...
- SQLState: 23000
今天登陆项目的时候,报500,日志显示如下: 解决办法是: 首先,删除序列:DROP SEQUENCE sys_log_seq 然后,新建序列:CREATE SEQUENCE sys_log_seq ...