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