(匹配)Fire Net --hdu --1045

链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1045

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#problem/A

一看原题,先用搜索写一下,还是要学学匹配吧!

以前的代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 10
#define INF 0x3f3f3f3f

int n, ans;
char G[N][N];

bool judge(int x, int y)
{
    int i;

    if(G[x][y]==‘X‘)
        return false;

    for(i=x; i>=0; i--)
    {
        if(G[i][y]==‘X‘)
            break;
        if(G[i][y]==‘D‘)
            return false;
    }

    for(i=y; i>=0; i--)
    {
        if(G[x][i]==‘X‘)
            break;
        if(G[x][i]==‘D‘)
            return false;
    }
    return true;
}

void DFS(int z, int k)
{
    int x, y;

    x = z/n;
    y = z%n;

    if(z==n*n)
    {
        ans = max(ans, k);
        return ;
    }

    if(judge(x, y))
    {
        G[x][y] = ‘D‘;
        DFS(z, k+1);
        G[x][y] = ‘.‘;
    }

    DFS(z+1, k);
}

int main()
{
    while(scanf("%d", &n),n)
    {
        int i;

        memset(G, 0, sizeof(G));
        for(i=0; i<n; i++)
            scanf("%s", G[i]);

        ans = 0;
        DFS(0, 0);

        printf("%d\n", ans);
    }
    return 0;
}
时间: 2024-10-28 17:56:45

(匹配)Fire Net --hdu --1045的相关文章

Fire Net HDU 1045

简单深搜,可以完全暴力,不会超时的. #include<iostream> #include<cstring> #include<cmath> using namespace std; #define MAX(a,b) (a>b?a:b) char maze[10][10]; int n, maxn; void DFS(int step,int count); int cheak(int x, int y); int main() { int i; while(s

A - Fire Net - hdu 1045(二分图匹配)

题意:一个阵地可以向四周扫射,求出来最多能修多少个阵地,墙不可以被扫射透,阵地不能同行或者或者列(有墙隔着例外) 分析:很久以前就做过这道题..当时是练习深搜来着,不过时间复杂度比较高,现在再看突然发现原来可以用二分图匹配来做,时间soso的 ****************************************************************** #include<stdio.h>#include<string.h>#include<algorit

Fire Net HDU - 1045(二分匹配)

把每一列中相邻的 .  缩为一个点 作为二分图的左边 把每一行中相邻的  .  缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉/// #include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <vector> #include <cmath> #include

Hdu 1045 二分匹配

题目链接 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6282    Accepted Submission(s): 3551 Problem Description Suppose that we have a square city with straight streets. A map of a city i

hdu 1045 Fire Net(最小覆盖点+构图(缩点))

http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1045 Description Suppose that we have a square city with straight streets. A map of a city

HDU 1045 - Fire Net (最大独立集)

题意:给你一个正方形棋盘.每个棋子可以直线攻击,除非隔着石头.现在要求所有棋子都不互相攻击,问最多可以放多少个棋子. 这个题可以用搜索来做.每个棋子考虑放与不放两种情况,然后再判断是否能互相攻击来剪枝.最后取可以放置的最大值. 这里我转化成求最大独立集来做. 首先将每个空地编号,对于每个空地,与该位置可以攻击到的空地连边.找最多的空地使得不互相攻击,即求该图的最大独立集.与搜索做法基本一致,但是说法略有不同. 1 #include<iostream> 2 #include<cstring

HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】

Fire Net Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1045 Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, e

HDU 1045 Fire Net 贪心

Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through wh

HDU 1045 DFS暴搜

Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6229    Accepted Submission(s): 3506 Problem Description Suppose that we have a square city with straight streets. A map of a city is a s