hdu149850 years, colors (multiple minimum vertex overlays)

Source: Internet
Author: User

Years, colorsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1516 Accepted Submission (s): 818


Problem Descriptionon 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.



Inputthere'll 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.

Outputfor 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 112 11 11 22 11 22 25 41 2 3 4 52 3 4 5 13 4 5 1 24 5 1 2 35 1 2 3 43 350 50 5050 50 5050 50 500 0

Sample Output
-1121 2 3 4 5-1

Test instructions: At the anniversary of the event, there are n*n a lattice, which has a different color of the balloon, so that students to shoot balloons, but at a time only to take a row or a row of the same color of the balloon. And a student can only take k times, ask those color balloons can not be shot in 4k times the color of the output balloons, in ascending order, assuming that there is no output-1.

Problem-solving: it seems impossible, but according to test instructions, we can separate the different colors of the balloons, each one of the balloons. This is a minimal top cover problem.

#include <stdio.h> #include <string.h>int map[55][105][105],vist[105],match[105],n;int find (int i,int c) {        for (int j=1;j<=n;j++) if (!vist[j]&&map[c][i][j]) {vist[j]=1; if (match[j]==0| |        Find (Match[j],c)) {match[j]=i; return 1; }} return 0;}    int main () {int m,c,cc[55];        while (scanf ("%d%d", &n,&m) >0&&n+m!=0) {memset (map,0,sizeof (map));        memset (Cc,0,sizeof (cc));        for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {scanf ("%d", &c); map[c][i][j]=1; cc[c]=1;        } int Flag=0,ans;            for (int c=1;c<=50;c++) if (Cc[c]) {ans=0; memset (match,0,sizeof (match));                for (int i=1;i<=n;i++) {memset (vist,0,sizeof (vist));            Ans+=find (I,C); } if (ans>m) {if (flag) printf (""); printf ("%d", c);            flag=1;  }        }      if (flag==0) printf ("-1");    printf ("\ n"); }}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

hdu149850 years, colors (multiple minimum vertex overlays)

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.