HDOJ 1498 - 50 years, 50 colors 水二分图..二分图最小点覆盖
来源:互联网 发布:手机虚拟声卡软件 编辑:程序博客网 时间:2024/05/21 17:24
题意:
在一个n*n的矩阵中(n<=100)..每个格子放了一种颜色的气球(颜色用数字1~50表示)...每次的操作是消除一行或者一列颜色相同的气球.问经过k次操作..哪些颜色的气球还存在...
题解:
每种颜色分开来求...做边(x,y)....由于对于一个气球(x,y)..只要它x被用了或者y被用了..那么这个气球也就消除了...题目转化为最少要用多少个点..使得所有的边都覆盖..也就是经典的二分图最小点覆盖问题...等价为求二分图的最大匹配数...
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;}
- HDOJ 1498 - 50 years, 50 colors 水二分图..二分图最小点覆盖
- hdoj 1498 50 years, 50 colors (二分图--最小点覆盖)
- HDOJ 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 二分图最小点覆盖
- HDU1498_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(二分最大匹配之最小点覆盖)
- 杭电 1498 50 years, 50 colors【二分匹配+最小点覆盖问题】
- 【杭电1498】50years,50colors二分最大匹配--最小点覆盖
- HDU-1498-50 years,50 colors【二分匹配】【最小顶点覆盖】
- WindowsPhone8常见问题及使用技巧
- POJ3753-一道水题
- iOS 数组排序
- java writelock 实例
- 2059龟兔赛跑
- HDOJ 1498 - 50 years, 50 colors 水二分图..二分图最小点覆盖
- 一直在问自己,到底想要什么?
- CentOS卸载系统自带的OpenJDK
- jadeclipse 反编译插件
- JFreeChart生成图表中文乱码问题解决方案
- 【问题记录】HP-Unix的async I/O导致产生大量tarce文件
- View---在现有页面中插入新的view
- 修复64位系统下adb启动出现/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 及类似问题
- 【Ubuntu】几个安装命令