Question:
In a matrix of n * n (n <= 100) .. each lattice is filled with a color balloon (the color is measured in numbers 1 ~ 50)... each operation is to remove one row or one column of balloons with the same color. After k operations, ask which balloons of the same color still exist...
Question:
Separate each color... side (x, y ).... because for a balloon (x, y ).. as long as x is used or y is used .. then this balloon will be eliminated... how many points should I use to convert a question .. overwrite all edges .. that is, the classic bipartite graph least Point Coverage problem... it is equivalent to finding the maximum number of matching for a bipartite graph...
Program:
#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#include<stack>#include<queue>#define ll long long#define MAXN 105using namespace std;int n,match[MAXN];bool arc[MAXN][MAXN],inmap[MAXN],used[MAXN],s[MAXN][MAXN]; bool dfs(int x){ int i; for (i=1;i<=n;i++) if (arc[x][i] && !used[i]) { used[i]=true; if (!match[i] || dfs(match[i])) { match[i]=x; return true; } } return false; }int getmax(){ int sum=0; memset(match,0,sizeof(match)); for (int i=1;i<=n;i++) { memset(used,false,sizeof(used)); sum+=dfs(i); } return sum;}int main(){ int i,j,k,ans; bool f; while (~scanf("%d%d",&n,&k) && n) { memset(inmap,false,sizeof(inmap)); for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf("%d",&s[i][j]),inmap[s[i][j]]=true; f=false; for (int t=1;t<=50;t++) if (inmap[t]) { memset(arc,false,sizeof(arc)); for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (s[i][j]==t) arc[i][j]=true; if (getmax()>k) { if (!f) printf("%d",t); else printf(" %d",t); f=true; } } if (!f) printf("-1"); printf("\n"); } return 0;}