hdu1498 50 years, 50 colors
来源:互联网 发布:mac imovie教程 编辑:程序博客网 时间:2024/05/01 16:41
很简单的求最小点覆盖、
code:
#include <set>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 110;int n,k;set<int> col;set<int>::iterator it;int ans[MAXN],cnt;bool graph[MAXN][MAXN];bool vis[MAXN];int link[MAXN],a[MAXN][MAXN];int find(int x){ int y; for(y=1;y<=n;y++) { if(graph[x][y] && !vis[y]) { vis[y]=true; if(!link[y] || find(link[y])) { link[y]=x; return true; } } } return false;}int solve(){ int x,num=0; for(x=1;x<=n;x++) { memset(vis,0,sizeof(vis)); if(find(x)) num++; } return num;}int main(){ int i,j; while(~scanf("%d%d",&n,&k) && (n+k)) { col.clear(); cnt=0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); col.insert(a[i][j]); } } for(it=col.begin();it!=col.end();it++) { memset(link,0,sizeof(link)); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(a[i][j]==(*it)) { graph[i][j]=1; }else{ graph[i][j]=0; } } } int t=solve(); if(t>k) { ans[++cnt]=(*it); //printf("max:%d col:%d \n",t,*it); } } if(!cnt) puts("-1"); else{ for(i=1;i<cnt;i++) printf("%d ",ans[i]); printf("%d\n",ans[cnt]); } } return 0;}
- hdu1498 50 years, 50 colors
- hdu1498 50 years, 50 colors--匈牙利算法
- hdu1498 50 years, 50 colors (最小点覆盖)
- hdu1498 50 years, 50 colors --- 最小点覆盖
- hdu1498--50 years, 50 colors(二分匹配,题意。。。)
- hdu1498 50 years, 50 colors(最小顶点覆盖)
- hdu1498—50 years, 50 colors(最小点覆盖)
- 50 years, 50 colors
- 50 years, 50 colors
- 50 years, 50 colors HDU
- hdu 149850 years, 50 colors
- hdu 1498 50 years, 50 colors
- hdu 1498 50 years, 50 colors
- HDU 1498 50 years, 50 colors
- 6.3.5 50 years, 50 colors
- HDU 1498 50 years, 50 colors
- 50 years, 50 colors(二分图)
- HDU 1498 50 years, 50 colors
- VBS学习2 + 如何在运行命令行工具后让命令窗口保持打开状态?
- Extjs4学习资料(TreeStore使用)
- redirect与forward区别
- C++ swap宏
- js刷新页面方法大全
- hdu1498 50 years, 50 colors
- 笔记-2003-A Maximum Entropy Chinese Character-Based Parser
- 微软strcpy,strcat和strcmp的实现源代码
- Struts1和struts2的执行流程
- 虚拟化、云计算、开放源代码及其他
- 《windows核心编程》读书笔记——内存体系结构
- 旧工程适配ios6和iphone5 之 适配ios6转屏
- solr4.0安装和简单导入mysql数据
- NYOJ - 次方求模