HDU-1498 50 years, 50 colors 最小点覆盖
来源:互联网 发布:小罐茶怎么样知乎 编辑:程序博客网 时间:2024/05/07 11:27
给你一个n*n的矩阵,每一行有一个颜色,颜色是1-50,每个人有k次机会,每次可以选择一排消除这一排所有的颜色,问最后有几种颜色没有被完全消掉,没有则输出-1.
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>#include <cmath>#include <algorithm>using namespace std;int map[111][111];int n,k,s;int link[111];int visit[111];bool dfs(int k)//寻找从k出发的可增广路 {int i,j;for(int i=1;i<=n;i++){if(map[k][i]==s&&!visit[i]){visit[i]=1;//加入增广路 j=link[i];if(j==-1||dfs(j))//j是未盖点 或者 从j的对应项出发有可增广路) {link[i]=k;return true;//k有可增广路,返回true;}}}return false;//则从k没有可增广路,返回false;}int hungary(){int num=0;memset(link,-1,sizeof(link));//初始化 for(int i=1;i<=n;i++){memset(visit,0,sizeof(visit));if(dfs(i))//有增广路 {num++;//匹配数++ }}return num;}int main(){int a[55],color[55];int cnt;while(scanf("%d%d",&n,&k)!=EOF){if(n==0&&k==0){break;}cnt=0;memset(map,0,sizeof(map));memset(color,0,sizeof(color));for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){scanf("%d",&map[i][j]);color[map[i][j]]++;}}for(int i=1;i<=50;i++){s=i;if(hungary()>k&&color[i]>0){a[cnt++]=i;}}if(cnt==0){cout<<"-1"<<endl;}else{for(int i=0;i<cnt-1;i++){printf("%d ",a[i]);}printf("%d\n",a[cnt-1]);}}return 0;}
0 0
- HDU 1498 50 years, 50 colors 最小点覆盖
- HDU-1498 50 years, 50 colors 最小点覆盖
- HDU 1498 50 years, 50 colors(最小点覆盖,坑题)
- HDU 1498 50 years, 50 colors 最小点覆盖
- hdoj 1498 50 years, 50 colors 【最小点覆盖】
- HDU 1498 50 years, 50 colors(多次进行最小点覆盖运算)
- HDU 1498 50 years, 50 colors(二分最大匹配之最小点覆盖)
- hdu 1498 50 years, 50 colors(二分图匹配--最小点覆盖)
- HDU 1498 50 years, 50 colors 二分图最小点覆盖(基础题)
- HDU 1498 50 years, 50 colors 二分图最小点覆盖
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 1498 50 years, 50 colors(最小覆盖点数)
- HDU 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 50 years, 50 colors(枚举点,最小点覆盖)
- hdu1498 50 years, 50 colors (最小点覆盖)
- hdu1498 50 years, 50 colors --- 最小点覆盖
- hdu1498—50 years, 50 colors(最小点覆盖)
- 信号量sem_t\sem_init\sem_post\sem_wait\sem_destroy
- [Leetcode] Divide Two Integers
- JS一维数组、多维数组和对象的混合使用
- 铁路栈问题
- Python 迭代器和生成器
- HDU-1498 50 years, 50 colors 最小点覆盖
- FPC关键字
- 上海传智播客JAVASE_day08学习笔记
- Mac OS X 10.9.4编译Protobuf-2.4.1问题
- OC-中介找房-代理设计模式
- 翻转快排
- 多线程详解
- 【android】SpannableString详解及使用SpannableString设置复合文本
- 淘宝2013面试题-求首尾相连数组的最大子数组和