HDU 4499 Cannon

题意:

思路:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
const int MAXN=10+5;
int n,m,Q,ans;
int mat[MAXN][MAXN];
void dfs(int x, int y, int cnt)
{
	if(x>=n)
	{
		ans=max(ans,cnt);
		return;
	}
	if(y>=m)
	{
		dfs(x+1,0,cnt);
		return;
	}
	if(mat[x][y])
	{
		dfs(x,y+1,cnt);
		return;
	}
	dfs(x,y+1,cnt);
	int t;
	bool flag=false;
	for(t=x-1;t>=0;t--)
		if(mat[t][y])
			break;

	for(int i=t-1;i>=0;i--)
	{
		if(mat[i][y])
		{
			if(mat[i][y]== 2)
			{
				flag=true;
			}
			break;
		}
	}
	if(flag)
	{
		return;
	}
	for(t=y-1;t>=0;t--)
	{
		if(mat[x][t])
			break;
	}
	for(int j=t-1;j>=0;j--)
	{
		if(mat[x][j])
		{
			if(mat[x][j]== 2)
			{
				flag=true;
			}
			break;
		}
	}
	if(flag)
	{
		return;
	}
	mat[x][y]=2;
	dfs(x,y+1,cnt+1);
	mat[x][y]=0;
}

int main()
{
	while(scanf("%d %d %d",&n,&m,&Q)!=EOF)
	{
		memset(mat,0,sizeof(mat));
		for(int i=0;i<Q;i++)
		{
		    int x,y;
			scanf("%d %d",&x,&y);
			mat[x][y]=1;
		}
		ans=0;
		dfs(0,0,0);
		printf("%d\n",ans);
	}
	return 0;
}
时间: 2024-10-13 16:58:08

HDU 4499 Cannon的相关文章

HDU 4499 Cannon (暴力搜索)

题意:在n*m的方格里有t个棋子,问最多能放多少个炮且每个炮不能互相攻击(炮吃炮) 炮吃炮:在同一行或同一列且中间有一颗棋子. #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <queue> #include <math.h> #define M 50 #define LL long long using

hdu 4499 Cannon(暴力)

题目链接:hdu 4499 Cannon 题目大意:给出一个n*m的棋盘,上面已经存在了k个棋子,给出棋子的位置,然后求能够在这种棋盘上放多少个炮,要求后放置上去的炮相互之间不能攻击. 解题思路:枚举行放的情况,用二进制数表示,每次放之前推断能否放下(会不会和已经存在的棋子冲突),放下后推断会不会互相攻击的炮,仅仅须要对每一个新加入的炮考虑左边以及上边就能够了. #include <cstdio> #include <cstring> #include <algorithm&

hdu 4499 Cannon 暴力dfs搜索

Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 338 Problem Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move

HDU 4499.Cannon 搜索

Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 965    Accepted Submission(s): 556 Problem Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move

hdu 4499 Cannon dfs

Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move horizontally or vertically along the chess grid. At eac

HDU 4499 Cannon (暴力求解)

题意:给定一个n*m个棋盘,放上一些棋子,问你最多能放几个炮(中国象棋中的炮). 析:其实很简单,因为棋盘才是5*5最大,那么直接暴力就行,可以看成一行,很水,时间很短,才62ms. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include &

HDU ACM 4499 Cannon 暴力DFS

分析:N和M很小,直接暴力搜索即可. #include<iostream> using namespace std; #define N 6 #define M 6 int vis[N][M]; //有炮设为2,无炮为0,其他为1 int n,m,q,ans; #define max(a,b) ((a)>(b)?(a):(b)) bool Valid(int i,int j) //只需要判断当前和前面的即可(行列) { int fg=0; int k; if(vis[i][j]==1)

HDOJ 4499 Cannon

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4499 oder?如何参加? Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 513    Accepted Submission(s): 297 Problem Description In Chinese Chess, th

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

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaces