HDU 1569 Squares Fetch (2) Maximum point weight Independent set

Source: Internet
Author: User

Check Count (2)

Time limit:10000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5425 Accepted Submission (s): 1695


Problem description gives you a m*n checkered checkerboard with a non-negative number in each lattice.
Take out a number of the number, so that the arbitrary two number of the lattice does not have a common edge, that is, the number of the 2 lattice is not adjacent, and the number of the maximum.

Input includes multiple test instances, each of which consists of 2 integers m,n and m*n non-negative numbers (M<=50,N<=50)

Output for each test instance, the maximum possible and

Sample INPUT3 375 15 21 75 15 28 34 70 5

Sample Output188 Link: http://acm.hdu.edu.cn/showproblem.php?pid=1569 Test instructions is to seek the maximum point right independent set. Reference paper: Http://wenku.baidu.com/link?url=8_Q5cEXSzr67Vdp8S9IlU9W91OIkr_ Aqhtx8ywhmtgkcasj7vu7soe3p7ub6g9ymktfwsbgssrjkf8owzg3agdnngqctscf1wz7ujplzpze Point Cover Set: is a point set of the graph G point, so that all edges in the graph have at least one endpoint within that set. Point stand-alone set: is a set of points for a non-graph, so that any two points in the collection are not adjacent to the original. The minimum point cover Set (minimum vertex covering set,minvcs) is the point overlay set with the fewest points in the graph. The maximum point independent set (maximum vertex independent Set,maxvis) is the point-independent set with the most points in the graph without direction. the above two problems can be solved quickly by using the maximum matching model in the two-part graph.   a more general question: The minimum point weight cover set (minimum weight vertex covering set,minwvcs) is a point overlay set with the smallest point weights in the graph G with point weights. The maximum point weight independent set (maximum weight vertex independent Set,maxwvis) is the maximum point independent set of point weights in the graph with point weights.   minimum point weight overlay problem mapping method: The source point S and the meeting point T are added based on the original point. Each edge in the two-dimensional graph is replaced by the capacity for positive infinity points with a forward edge. adds a forward edge to the midpoint of the S-to-X collection, with a weight of that point. Adds a point in the collection Y to the forward edge of T, and the capacity is the weight of that point. Then the minimum cut is asked.   Maximum point Independent set = Complete set-Minimum point overlay Maximum point weight independent set = Complete set-Minimum point weight cover sets The sum of the right of the maximum point right independent set point = The sum of the right--the sum of the right of the minimum point weight covering set pointTherefore, the maximum point weight independent set is the complete-minimum point weight coverage set. Then divide the points in the squares into two parts x and Y. Increase the source point S and the meeting point T. The x and y point edges, that is, the points in X are connected to the points in their neighboring Y points with a forward edge. The S-to-X-point edge is the weighted value for each point. Y to T point edge for each point weight. The edge capacity of X to Y is positive infinity. This can be considered because the points in X are connected to the edges of the points in the y adjacent to it and are not allowed in the topic. So it is the equivalent of choosing such an illegal edge and then removing the smallest point. So the rest is the biggest point.
#include <bits/stdc++.h>using namespace std; #define MAXN 55const int inf = 0x3f3f3f3f;int M, N;int mp[maxn][maxn];in    T Mark[maxn][maxn];int dir[4][2] = {{0, 1}, {1, 0}, {0,-1}, {-1, 0}};struct edge{int from, to, cap, flow;    Edge (int f, int t, int c, int fl) {from = f; to = t; cap = c; flow = FL; }};vector <Edge> edges;vector <int> g[maxn*maxn];int s, t, N, M;int CUR[MAXN*MAXN], VIS[MAXN*MAXN], D[maxn*ma    Xn];void Addedge (int from, int. to, int caps) {Edges.push_back (Edge (from, to, Cap, 0));    Edges.push_back (Edge (to, from, 0, 0));    m = Edges.size ();    G[from].push_back (m-2); G[to].push_back (m-1);}    BOOL BFs () {memset (Vis, 0, sizeof (VIS)); D[s] = 0;    Vis[s] = 1;    Queue <int> q;    Q.push (s);        while (!q.empty ()) {int u = q.front (); Q.pop ();            for (int i = 0; i < g[u].size (); i++) {Edge &e = edges[g[u][i]]; if (!vis[e.to] && e.cap > E.flow) {vis[E.to] = 1;                D[e.to] = d[u]+1;            Q.push (e.to); }}} return vis[t];}    int dfs (int x, int a) {if (x = = T | | a = = 0) return A;    int flow = 0, F;        for (int &i = cur[x]; i < g[x].size (); i++) {Edge &e = edges[g[x][i]];            if (d[x]+1 = = D[e.to] && (f = dfs (e.to, Min (A, e.cap-e.flow))) > 0) {e.flow + = f;            Edges[g[x][i]^1].flow-= f;            Flow + + F;            A-= f;        if (a = = 0) break; }} return flow;}    int Maxflow () {int flow = 0;        while (BFS ()) {memset (cur, 0, sizeof (cur));    Flow + = DFS (s, INF); } return flow;}    BOOL Judge (int x, int y) {if (x >= 1 && x <= N && y >= 1 && y <= M) return true; return false;}        int main () {while (~scanf ("%d%d", &n, &m)) {edges.clear ();        for (int i = 0; i < MAXN*MAXN; i++) g[i].clear ();        int sum = 0; for (int i = 1; I <= N;                i++) {for (int j = 1; J <= M; j + +) {scanf ("%d", &mp[i][j]);            Sum + = Mp[i][j]; }} s = 0;        t = n*m+1; for (int i = 1, i <= N; i++) {for (int j = 1; J <= M; j + +) {if (i+j)%2 =                        = 0) {Addedge (S, (i-1) *m+j, mp[i][j]);                    if (i > 1) addedge ((i-1) *m+j, (i-2) *m+j, INF);                    if (J > 1) Addedge ((i-1) *m+j, (i-1) *m+j-1, INF);                    if (i < N) Addedge ((i-1) *m+j, I*M+J, INF);                if (J < M) Addedge ((i-1) *m+j, (i-1) *m+j+1, INF);            } else Addedge ((i-1) *m+j, T, Mp[i][j]);    }} printf ("%d\n", Sum-maxflow ()); }}

HDU 1569 Squares Fetch (2) Maximum point weight Independent set

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.