标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1695 Accepted Submission(s): 931
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 const int maxn = 110; 5 int ma[maxn][maxn]; 6 int line[maxn],res[maxn]; 7 bool vis[maxn],bj[maxn]; 8 int k,n,m,t; 9 template <class T> 10 void init(T a){ 11 memset(a,0,sizeof(a)); 12 } 13 int match(int st,int u) 14 { 15 for(int v = 1;v<=n;v++) 16 { 17 if(ma[u][v]== st && !vis[v]) 18 { 19 vis[v] = 1; 20 if(line[v]==-1 || match(st,line[v])) 21 { 22 line[v] = u; 23 return 1; 24 } 25 } 26 } 27 return 0; 28 } 29 int cmp(const void *a,const void *b){ 30 return *(int *)a - *(int *)b; 31 } 32 int K_M(int st) 33 { 34 memset(line,-1,sizeof(line)); 35 int ans = 0; 36 for(int i = 1;i<=n;i++){ 37 init(vis); 38 ans += match(st,i); 39 } 40 return ans; 41 } 42 int main() 43 { 44 int t; 45 while(~scanf("%d%d",&n,&k)) 46 { 47 if(n==0 && k== 0) break; 48 init(ma); init(res); init(bj); 49 for(int i = 1;i<=n;i++) 50 { 51 for(int j = 1;j<=n;j++) 52 { 53 scanf("%d",&t); 54 ma[i][j] = t; 55 if(!bj[t]) 56 bj[t] = 1; 57 } 58 } 59 int cnt,num = 0; 60 for(int i = 1;i<=55;i++) 61 { 62 if(bj[i]){ 63 cnt = K_M(i); 64 (cnt>k)?(res[num++] = i):(1); 65 } 66 } 67 if(num==0) puts("-1"); 68 else{ 69 qsort(res,num,sizeof(res[0]),cmp); 70 for(int j = 0;j<num-1;j++) 71 printf("%d ",res[j]); 72 printf("%d\n",res[num-1]); 73 } 74 } 75 return 0; 76 }
hdu----149850 years, 50 colors(最小覆盖点),布布扣,bubuko.com
hdu----149850 years, 50 colors(最小覆盖点)
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/gongxijun/p/3928738.html