hdu149850 years, colors (good question)

Source: Internet
Author: User
years, Colors Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1971 Accepted Submission (s): 1089



Problem Description on Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nice, Isn ' t it? To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there'll be a game named "Crashing Color Balloons".

There'll is a n*n matrix board on the ground, and each grid would have a color balloon in it. and the color of the ballon is in the range of [1, 50]. After the referee shouts ' go! ', you can begin to crash the balloons. Every time you can only choose one kind of balloon to crash, we define that the both balloons with the same color belong to The same kind. What's more, each time you can is choose a single row or column of balloon, and crash the balloons that with the color Y Ou had chosen. Of course, a lot of students is waiting to play this game, so we just give every student K times to crash the balloons.

Here comes the Problem:which kind of balloon are impossible to being all crashed by a student in K times.



Input there would be multiple input cases. Each test case begins with the integers n, K. N is the number of rows and columns of the balloons (1 <= n <=), a nd k is the Times, ginving to each student (0 < K <= N). Follow a matrix A of n*n, where Aij denote the color of the ballon in the I row, j column. Input ends with n = k = 0.

Output for each test case, print in ascending order all the colors of which is impossible to being crashed by a student in K Times. If There is no choice, print "-1".

Sample Input
1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 5 4 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3 5 1 2 3 4 3 3 50 50 50 50 50 50
Sample Output
-1 1 2 1 2 3 4 5-1
Author 8600

Think for a while actually already thought of the row and column distribution, also thought of the enumeration color, but did not think of the row and columns to build a binary map,
Because each point is taken, the edge between the row and column must be taken, which is the minimum point overlay
#include <bits/stdc++.h> const int maxn=12000;
const int maxm=4000010; struct edge{int to,next;}
EDGE[MAXM];
int tot;
int mp[151][151];
BOOL USED[MAXN];
int LINKER[MAXN];

int HEAD[MAXN];
    void Init () {tot=0;
memset (head,-1,sizeof (head));
    } void Addedge (int u,int v) {edge[tot].to=v;
    Edge[tot].next=head[u];
head[u]=tot++;
        } bool Dfs (int u) {for (int i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].to;
            if (!used[v]) {used[v]=true; if (linker[v]==-1| |
                DFS (Linker[v])) {linker[v]=u;
            return true;
}}} return false;
    } int Hungary (int n) {memset (LINKER,-1,SIZEOF (linker));
    int ret=0;
        for (int u=1;u<=n;u++) {memset (used,false,sizeof (used));
    if (DFS (U)) ret++;
} return ret;
    } int main () {int k,n,m;
    int u,v;
        while (scanf ("%d%d", &n,&m)!=eof) {if (n==0&&m==0) break; FoR (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {scanf ("%d", &mp[i][j]);
        } int flag=0;
            for (int k=1;k<=50;k++) {init ();
                        for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) if (mp[i][j]==k) {
                    Addedge (I,j+n);
            }} int ans=hungary (n);
                if (ans>m) {if (flag==1) printf ("%d", k);
                    else{flag=1;
                printf ("%d", k);
        }}} if (flag==1) printf ("\ n");
    else printf (" -1\n");
} return 0;
 }/* 3 2 6 7 8 8 7 6 8 7 6 * *


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.