UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
来源:互联网 发布:mac 重装 u盘 编辑:程序博客网 时间:2024/06/08 00:22
题意是删掉一些点使得两个集合没有整除关系,并且保证删的点最少。
即是求最小覆盖点集,即是求最大二分匹配。
二分匹配的几个重要定理:
最小覆盖点数 = 最大匹配数
最大独立集 = 点数 - 最大匹配数
最小路径覆盖 = 点数 - 最大匹配数
最小覆盖点数:假如选了一个点就相当于覆盖了以它为端点的所有边,你需要选择最少的点来覆盖所有的边。
最小路径覆盖:在一个N*N的有向图中,路径覆盖就是在图中找一些路经,使之覆盖了图中的所有顶点, 且任何一个顶点有且只有一条路径与之关联;(如果把这些路径中的每条路径从它的起始点走到它的终点那么恰好可以经过图中的每个顶点一次且仅一次);如果不考虑图中存在回路,那么每每条路径就是一个弱连通子集.
独立集:独立集:图中任意两个顶点都不相连的顶点集合。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <set>#include <vector>#include <map>#include <queue>#include <stack>#include <algorithm>using namespace std;typedef long long LL;const int N = 100+10;vector<int>g[N];bool vis[N];int from[N];map<LL,int>mymap;bool match(int x)//here{ for(int i=0;i<g[x].size();i++) { int v = g[x][i]; if(vis[v]) continue; vis[v] = true; if(from[v] == -1 || match(from[v])) { from[v] =x; return true; } } return false;}int main(){ int T; scanf("%d",&T); for(int cas = 1;cas<=T;cas++) { int n; scanf("%d",&n); for(int i=0;i<=n;i++) g[i].clear(); mymap.clear(); memset(from,-1,sizeof(from)); for(int i=1;i<=n;i++) { LL x; scanf("%lld",&x); mymap[i] = x; } scanf("%d",&n); for(int i=1;i<=n;i++) { LL x ; scanf("%lld",&x); for(map<LL,int>::iterator it = mymap.begin();it!=mymap.end();it++) { if(x%(it->second)==0) { g[it->first].push_back(i); } } } int cnt = 0; for(map<LL,int>::iterator it = mymap.begin();it!=mymap.end();it++)//here { memset(vis,false,sizeof(vis)); if(match(it->first)) cnt++; } printf("Case %d: %d\n",cas,cnt); } return 0;}
0 0
- UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
- UVa11159 - Factors and Multiples(二分匹配)
- LightOJ 1149 Factors and Multiples 最大匹配--匈牙利算法
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- LightOJ - 1149 Factors and Multiples(二分图匹配)
- lightoj1149 - Factors and Multiples【二分图最大匹配】
- light oj 1149 - Factors and Multiples (二分匹配)
- Factors and Multiples(二分图匹配)LightOJ
- Light oj 1149 - Factors and Multiples 【二分图最大匹配】【好题】
- Light oj 1149--Factors and Multiples【二分匹配 && 经典建图】
- LightOJ--1149--Factors and Multiples(二分图好题)
- Light oj 1149 - Factors and Multiples【最大匹配】
- 二分匹配 ---- 匈牙利算法
- 二分匹配,匈牙利算法
- 二分匹配 匈牙利算法
- uva 11159 Factors and Multiples
- uva 11159 Factors and Multiples
- POJ1466 Girls and Boys(二分匹配 匈牙利算法)
- 只要是走 都要表示一下
- 文章标题
- 七牛CEO许式伟:服务端开发那些事儿
- latex算法步骤如何去掉序号
- java 异常 集合
- UVa11159 - Factors and Multiples(二分匹配匈牙利算法)
- leetcode122 Best Time to Buy and Sell Stock II
- CSS3 Animation 帧动画
- POJ 2449 Remmarguts' Date(第k短路+spfa+A*搜索)
- python 对文件做类别标签
- HDOJ 2010 水仙花数
- hdu 1013
- yum 快速搭建lnmp环境
- 水生火热的互联网金融