poj 1719 Shooting Contest 二分图匹配的一种特殊情况
来源:互联网 发布:wrecking ball网络翻唱 编辑:程序博客网 时间:2024/05/17 23:58
题意:
给一个r行c列的网格,其中一些格子可以选,要选一种方案,满足:1,每行至少选一个。2,每列恰好选一个。
分析:
二分匹配,特殊的地方在于每行至少要选一个。可以先做一次二分匹配,保证每行匹配好,然后对于没匹配的列任意匹配。
代码:
//poj 1719//sep9#include<iostream>using namespace std;const int maxN=1024; int M,v1,v2;bool g[maxN][maxN];bool vis[maxN];int link[maxN];bool dfs(int x){for(int y=1;y<=v2;++y)if(g[x][y]&&!vis[y]){vis[y]=true;if(link[y]==0||dfs(link[y])){link[y]=x;return true;}}return false;}void hungary(){for(int x=1;x<=v1;++x){memset(vis,false,sizeof(vis));if(dfs(x))++M;}return ;}int main(){int cases;scanf("%d",&cases);while(cases--){memset(g,false,sizeof(g));memset(link,0,sizeof(link));int i,j,r,c;scanf("%d%d",&r,&c);for(i=1;i<=c;++i){int x1,x2;scanf("%d%d",&x1,&x2);g[x1][i]=1;g[x2][i]=1;}M=0;v1=r,v2=c;hungary();if(M<r)printf("NO\n");else{for(i=1;i<=c;++i)if(!link[i])for(j=1;j<=r;++j)if(g[j][i])link[i]=j;for(i=1;i<=c;++i)printf("%d ",link[i]);printf("\n");}}return 0;}
0 0
- poj 1719 Shooting Contest 二分图匹配的一种特殊情况
- poj 1719 Shooting Contest 二分匹配
- [二分匹配]poj 1719 Shooting Contest
- POJ 1719 Shooting Contest 二分匹配
- POJ 1719 Shooting Contest 二分匹配
- poj 1719 Shooting Contest 二分匹配 匈牙利
- POJ 1719 Shooting Contest 二分图最大匹配
- POJ 1719 Shooting Contest(二分图匹配)
- POJ - 1719 Shooting Contest 二分图最大匹配
- Shooting Contest(POJ-1719)(二分最大匹配)
- POJ1719- Shooting Contest(二分图最大匹配)
- POJ题目1719 Shooting Contest(二分图)
- POJ--1719[Shooting Contest] 有源汇上下界可行流或二分匹配
- POJ 1719 Shooting Contest
- poj 1719 Shooting Contest
- poj 1719 Shooting Contest
- poj 1719Shooting Contest
- poj 1719 Shooting Contest
- online_judge_1164
- nmon使用方法
- oracle&字符的转义
- 在ASP.NET MVC 4中使用TWITTER BOOTSTRAP
- Windows 消息列表
- poj 1719 Shooting Contest 二分图匹配的一种特殊情况
- postgreSQL 里常用的查看表空间,数据库实例大小
- Eclipse可视化插件WindowBuilder的安装与使用
- Hadoop开发第1期---HDFS 的shell操作
- Linux命令学习:rm
- JavaScript教程大纲
- JavaScript学习(六)
- Unity游戏开发实战视频教程
- Redis Twitter Example