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 ...
随机推荐
- jQuery 表格隔行变色插件
jQuery提供了用于扩展jQuery功能的方法,即jQuery.fn.extend()方法和jQuery.extend()方法. 基本的JS框架代码如下: ;(function($) { $.fn. ...
- bzoj 1724: [Usaco2006 Nov]Fence Repair 切割木板【堆】
如果反着看,看成合并木板,就和合并果子一样了,把若干块放进一个小根堆,然后每次取出两个合并,把合并结果加进答案和堆里 代码里小根堆用优先队列实现(懒 #include<iostream> ...
- ECMA里面的一元符
只能操作一个值的叫做一元操作符.一元操作符是ECMAScript中最简单的操作符 1.递增和递减操作符 递增和递减操作符直接借鉴自c,而且各有俩个版本,前置型和后置型.顾名思义,前置型就是位于要操作的 ...
- [App Store Connect帮助]三、管理 App 和版本(7)移除 App
若要在“我的 App”主视图中移除 App,要先将此 App 从 App Store 中移除,并将所有与之关联的 App 内购买项目下架. 此外,仅当 App 的所有版本均处于下列状态之一时方可移除: ...
- swoole之 swoole_process 应用于TP框架
swoole_process 实现了多进程的管理,多个进程同时进行采集任务, 公司的框架比较low,用的tp框架,结合tp框架实现多进程的采集 这是swoole好的学习资源 https://segme ...
- window后台运行java jar文件
第一种需要一直开着dos界面: java -jar jar文件路径 第二种无需一直开着dos界面: 1.新建my-service.bat文件,内容如下: @echo off START "m ...
- ACM_Fibonacci数(同余)
Fibonacci数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 斐波那契数列定义如下:f(0)=0,f(1)=1,f(n+2 ...
- ACM_闹钟人生(水题)
闹钟人生 Time Limit: 2000/1000ms (Java/Others) Problem Description: 已知一个时钟一开始指向0点,顺时针走了n个小时,求它最终所指向的数字(时 ...
- 【转】mysql中select用法
转自:http://blog.sina.com.cn/s/blog_a74f39a201013c3b.html 1.选择所有的记录 select * from table_name; 其中*表示表中的 ...
- 转】 Spark SQL UDF使用
原博文出自于: http://blog.csdn.net/oopsoom/article/details/39401391 感谢! Spark1.1推出了Uer Define Function功能,用 ...