hdu1498 minimum Point coverage

Source: Internet
Author: User

1. Test instructions: (It is important to understand that test instructions can be converted to a minimum point coverage of the idea), for a n*n matrix, there are a number of different colors of the balloon (with the 1~50 tag kind), give you k chance, each opportunity can be a row or a column of a certain color wiped out, ask you after the elimination of k Times, What colors are you can't finish .... Take the case of the topic and draw:


We only have a k=1 chance to eliminate, we have only four ways, to see, 1 times we can not eliminate all 1th colors, but there can be 2nd color elimination of the situation

2. Analysis: So for the topic, our solution is to enumerate all the colors in the graph once, such as the enumeration I color, then the first to find out all the minimum number of colors to be used to eliminate, then for solving this minimum number of times ... We will consider using the binary matching Hungarian algorithm, and is a "minimum point coverage" of the idea

#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define MAX 101int n,k; The value of int map[max][max];//storing the entire figure map[i][j] is the color int link[max];bool color[max],vis[max];//color[i] of the square is true Indicates that the I color appears in the entire map bool Dfs (int i,int CO)//In this DFS process is the line I color for Co to match, {for (int j = 0; J < N; j + +) {if (!vis[j] && ma P[I][J] = = CO) {Vis[j] = true;if (Link[j] = = 1 | | DFS (LINK[J],CO)) {Link[j] = I;return true;}} return false;} memset (int co) {link,-1,sizeof (link)), int ans=0;for (int i = 0; i < n; i + +) {memset (vis,false,sizeof (VIS)); if (Dfs (I,co)) ans++;} return ans;} int main () {int I,j;int ans[51],tol;//ans[] holds the color number that is not to be eliminated, Tol indicates the number of colors that cannot be eliminated while (scanf ("%d%d", &n,&k), n+k) { memset (color,false,sizeof (color)); memset (map,0,sizeof (map)); for (i = 0; i < n; i + +) {for (j = 0; J < N; j + +) {scanf ("% D ", &map[i][j]); Color[map[i][j]] = true;}} Tol=0;for (i = 1; I <=, i + +) {if (Color[i])//Note here is whether the I color is a {if (KM (i) > K)//if the match min elimination I color is used more than k means can not be eliminated ans[tol+ +]=i;}} SORT (ans,ans+tol);//Note sort if (tol = = 0) printf ("-1"), elsefor (i = 0; i < tol; i + +) i = = 0? printf ("%d", Ans[i]):p rintf ("%d", ans[i]);//Here is a simple format control, there are spaces in both data printf ("\ n");} return 0;}


hdu1498 minimum Point coverage

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.