POJ2226 Muddy Fields "the smallest point overlay of a binary graph"

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2226


Main topic:

There is a field consisting of a grid of r rows C columns. There are several squares full of muddy water, the rest of the squares are grass. To use a width of 1, length

Any of the long planks covered with muddy water, but could not cover the grass, but only by row or column coverage, not diagonal

Covered. Q: At least how many planks to use.


Ideas:

This problem feels very difficult to think about. Looked at the online solution, incredibly clever structure of the two-point map to solve, is very subtle. We put the same line

A continuous mud grid as a vertex, these points as a set of two graphs, and then the same column of a continuous mud grid

As a vertex, these points are used as another set of two-part graphs. If the points of the two collection intersect, an edge is created. Two sets

The intersection shows where the Intersect is on the original a muddy grid, and the edges and the muddy squares become one by one of the corresponding relationship. If you have selected

An edge (plank), all the mud squares associated with that edge (plank) are overwritten. Then the problem becomes the minimum point set of the solution binary graph

Covered. The minimum point set coverage of the dichotomy graph = Two The maximum matching of the graph, which is solved by the Hungarian algorithm.

There is a place to pay attention to this problem, that is, the number of binary map points. Considering that the original size is 55*55, and the continuous slurry grid

do a point, now in order to find out the maximum number of points, assuming that all the mud and water squares are discontinuous, that is, each mud box is independent,

All around the lawn. There are up to 23*23+22*22 = 1013 points, which is the number of one set point for the two-minute chart.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int maxn = 1016;bool map[maxn][maxn],mask[maxn];int nx,ny;int cx[maxn],cy[maxn];char G[60][60];int fa[60][60] , Fb[60][60];int findpath (int u) {for (int i = 0; i < NY; ++i) {if (Map[u][i] &&!            Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | |                Findpath (Cy[i])) {Cy[i] = u;                Cx[u] = i;            return 1; }}} return 0;}    int Maxmatch () {for (int i = 0; i < NX; ++i) cx[i] = 1;    for (int i = 0; i < NY; ++i) cy[i] = 1;    int res = 0;                for (int i = 0, i < NX; ++i) {if (cx[i] = = 1) {for (int j = 0; j < NY; ++j)            MASK[J] = 0;        Res + = Findpath (i); }} return res;}    int main () {int n,m;      while (~SCANF ("%d%d", &n,&m)) {for (int i = 0; i < N; ++i)      scanf ("%s", G[i]);        memset (fa,0,sizeof (FA));        memset (fb,0,sizeof (FB));        memset (map,0,sizeof (MAP));        int n = 0;            for (int i = 0; i < N; ++i) {int sum = 0; for (int j = 0; j < M; ++j) {if (g[i][j] = = ' * ') {Fa[i][j]                    = N;                if (g[i][j+1]!= ' * ') n++;        }}} int m = 0; for (int i = 0, i < M; ++i) {for (int j = 0; j < N; ++j) {if (g[j][i] = =                    ' * ') {fb[j][i] = m;                if (g[j+1][i]!= ' * ') m++; }}} for (int i = 0, i < N; ++i) for (int j = 0; j < M; ++j) if (g[        I][J] = [' * ') map[fa[i][j]][fb[i][j]] = 1;        NX = N,ny = m;    printf ("%d\n", Maxmatch ()); } return 0;}


POJ2226 Muddy Fields "the smallest point overlay of a binary graph"

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.