hdu1498 years, Colors---min. coverage

Source: Internet
Author: User

Give a matrix with some balloons in different colors. Every time you can destroy a row or a column of a color balloon, ask you in k times and within, what color balloons are no matter what the end.

The idea, then, is to ask for the minimum coverage for each color balloon. >k is the answer.

Equivalent to the poj3041 version, because not every point in the matrix is equivalent.


#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include < algorithm> #include <vector> #include <queue> #include <map>const int maxn=105;using namespace STD; int mx[maxn],my[maxn],vis[maxn],e[maxn][maxn],n,cnt,mp[maxn][maxn],mat[maxn],ans[maxn];map<int,int> MMP;    int path (int i) {int J;            for (j=0;j<n;j++) {if (E[i][j]&&!vis[j]) {vis[j]=1; if (my[j]==-1| |                Path (My[j])) {mx[i]=j;                My[j]=i;            return 1; }}} return 0;}    int hungry () {int res=0;    memset (mx,-1,sizeof MX);    memset (my,-1,sizeof my);            for (int i=0;i<n;i++) {if (mx[i]==-1) {memset (vis,0,sizeof vis);        Res+=path (i); }} return res;}    int main () {int k,i,j,m,p,x; while (scanf ("%d%d", &n,&k) && (n| |        k)) {cnt=1;        Mmp.clear (); for (i=0;i<n;i++)           for (j=0;j<n;j++) {scanf ("%d", &mp[i][j]);                if (Mmp[mp[i][j]]) continue;                    else {mmp[mp[i][j]]=cnt;                MAT[CNT++]=MP[I][J];        }} m=0;            for (p=1;p<cnt;p++) {x=mat[p];            memset (e,0,sizeof e);            for (i=0;i<n;i++) for (j=0;j<n;j++) if (mp[i][j]==x) e[i][j]=1;        if (hungry () >k) ans[m++]=x;        } if (m==0) printf (" -1\n"); else {sort (ans,ans+m);//wa once.

。 printf ("%d", ans[0]); for (i=1;i<m;i++) printf ("%d", ans[i]); Puts (""); }} return 0;}



hdu1498 years, Colors---min. 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.