POJ 3041 asteroids (binary graph max match = = minimum point coverage)

Source: Internet
Author: User


should belong to the most basic matching problem, the focus is why the row and column can be divided into the left and right of the two sets, understanding for a long time, you can try to understand: A bomb can only blow up a row or a column, the left and right two sets of values represent a row or a column, respectively, Because the meaning of the connection is that if a row of a column locks the value of a planet is connected, we require a minimum number of bombs that is the smallest amount of rows and columns of the sum of the selected minimum number of rows and columns from the left and right two sets, these rows and columns meet the requirements are able to cover all the edges, In other words, these rows and columns of bombs can blow up all the planets. So essentially it becomes the smallest point set covering = = maximum number of matches.

/*=============================================================================## Author:liangshu-cbam # # QQ        : 756029571 # # School: Harbin Polytechnic University # # last modified:2015-08-27 16:22## filename:c.cpp## Description: # The people who is crazy enough to think they can change the world, is the ones who does! =============================================================================*/# #include <iostream> # include<sstream> #include <algorithm> #include <cstdio> #include <string.h> #include <c ctype> #include <string> #include <cmath> #include <vector> #include <stack> #includ e<queue> #include <map> #include <set> using namespace Std;int N, k;const int INF = 505;int from[ Inf],tot;bool use[inf];vector<int>g[inf];bool Match (int x) {for (int i = 0; i < g[x].size (); i++) {if (!u            Se[g[x][i]]) {Use[g[x][i]] = 1; if (from[g[X][i]] = =-1 | |                Match (From[g[x][i]])) {From[g[x][i]] = x;            return 1; }}} return 0;}    int Hungary () {tot = 0;    Memset (from, 255, sizeof (from));        for (int i = 1; I <= N; i++) {memset (use, 0, sizeof (use));    if (Match (i)) ++tot; } return tot;}        int main () {while (scanf ("%d%d", &n, &k)! = EOF) {for (int i = 0; i < K; i++) {int A, B;        scanf ("%d%d", &a, &b);    G[a].push_back (b);    } int ans = Hungary ();    cout<<ans<<endl;    for (int i = 0; i < INF; i++) {g[i].clear (); }} return 0;} /* 3 4 1 1 1 3 3 1 2 2 * *


Asteroids
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17878 Accepted: 9742

Description

Bessie wants to navigate she spaceship through a dangerous asteroid field in the shape of an n x N grid (1 <= N <= 5 ). The grid contains K asteroids (1 <= k <=), which is conveniently located at the lattice points of the G Rid.

Fortunately, Bessie have a powerful weapon that can vaporize all the asteroids on any given row or column of the grid with A single shot. This weapon was quite expensive, so she wishes to use it sparingly. Given the location of the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate a ll of the asteroids.

Input

* Line 1:two integers N and K, separated to a single space.
* Lines 2..k+1:each line contains, space-separated integers R and C (1 <= R, c <= N) denoting the row and column Coordinates of an asteroid, respectively.

Output

* Line 1:the integer representing the minimum number of times Bessie must shoot.

Sample Input

3 41 11 32 23 2

Sample Output

2

Hint

INPUT DETAILS:
The following diagram represents the data, where "X" is a asteroid and "." is empty space:
x.x
. X.
. X.

OUTPUT DETAILS:
Bessie may fire across row 1 to destroy the asteroids at (all) and (1,3), and then she could fire down column 2 to destroy T He asteroids at (2,2) and (3,2).

Source


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 3041 asteroids (binary graph max match = = minimum point coverage)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.