Hdu 1498, years, colors binary match

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


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


Test instructions: There are 1-50 colors of balloons on the map of N*n.  Ask which color balloons can not be eliminated in the K-step. Each step can eliminate a row or a column of this color balloon.

Practice: A simple binary match, each color is a two-point match, the maximum match is the minimum vertex coverage, that is, the need to eliminate all the minimum number of steps of this color. And the size of the k ratio is possible.

#include <stdio.h> #include <string.h> #define N-Visit[n int];
int mark[n];
int match[n][n];
int n,m,k;
    int dfs (int x) {int i; for (i=1;i<=m;i++)//Check the left node X with the node on the right {if (!visit[i]&&match[x][i]) {visit[i]= 1;//Mark checked points if (mark[i]==-1| | DFS (Mark[i])//mark If there is no male, directly to a husband, if there is a husband, search his husband there is no like, there are words, the woman with a new man; {//| | The front is not running behind; Mark[i]
            =x;//modify the matching relationship return 1;
}}} return 0;
	} int Hungary () {memset (mark,-1,sizeof (Mark));
    int max=0,j;
		for (j=1;j<=n;j++)//To make a partial vertex by traversing {memset (visit,0,sizeof (visit));
	if (Dfs (j)) max++;
} return max;
} int mp[150][150];
    int main () {int i,max; while (scanf ("%d%d", &n,&k), n| |
			K)//k with {for (int. i=1;i<=n;i++) {for (int j=1;j<=n;j++) {scanf ("%d", &mp[i][j]);
        }} m=n;
		int fir=1; for (int col=1;col<=50;col++) {memset (match,0,sizeof (match));
					for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (mp[i][j]==col) {match[i][j]=1;
			}}} max=hungary ();
					if (max>k) {if (FIR) {fir=0;
				printf ("%d", col);
			} else printf ("%d", col);
		}} if (FIR) puts ("-1");
    Else puts ("");
} return 0;
}/*http://blog.csdn.net/leolin_/article/details/7199688 in the binary diagram: The variable description involved in the program: N is the number of the left part of the two-point graph (vertex 1 to N), M is the number of vertices of the right part of the two graph (vertex designator is 1-m), and K is the number of paired relationships between the left and right vertices (stored in match two-dimensional array); minimum edge overlay = maximum Independent set = number of vertices n-minimum vertex overlay (maximum match) "maximum independent number of graphs": Select K top from v Vertex The K-tops are not next to each other.
So the largest k is the maximum independent number of the graph.
"Maximal Group of Graphs": the K-Top is selected from the V-Vertex, which makes the K-top form a complete picture, that is, any two top of the sub-graph has a direct edge. "Minimum Path overlay (the original image is not necessarily a binary graph, but must be a forward graph, split construction dichotomy)": find some paths in the diagram that cover all the vertices in the graph, and that any vertex has and only one path associated with it. Minimum path override = | v| -Maximum match number "minimum edge overlay (Original is a binary chart)": Find some edges in the diagram to cover all the vertices in the graph, and any one vertex has and only one edge associated with it. Minimum edge overlay = maximum Independent set = | v|
-Maximum match number "minimum vertex overlay": Use the fewest points (the points on both sides of the left and right) to associate each edge with at least one point. Maximum group = maximum independent set minimum side overlay of the complement graph = Two graph maximum Independent set = | v| -Minimum path overlay//two min path overlay = | v| -Maximum number of matches//graph minimum Vertex overlay = maximum number of matches minimum vertex overlay + maximum Independent number= |

v|
Minimum cut = minimum point weight cover set = Point right and-Maximum point weight independent set *//* (1) Minimum point path Overlay: A direction graph, with a minimum of no intersection (one point only go through) the edges of all the points covered. Set up a new diagram, each point I in the G in the new diagram to split into two points I ', I ', if there is an edge <i in G, j> in the new diagram with the <i ', j ';, obviously the new figure is a binary graph, the maximum match, then (n-New graph maximum matching value)
is the minimum point path override value. Time complexity: O (NM) (Hungary algorithm) */








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.