二分匹配_HDU_2768
来源:互联网 发布:美图秀秀抠图软件 编辑:程序博客网 时间:2024/06/06 05:02
/*应该是二选一的问题,在宠物爱好上有冲突的,就必须二选1,就有一条边最后就是求最大独立点集合非二分图的最大匹配,link[u] = ,link[v] = ,不为*/#include<iostream>#include<cstdio>#include<cstring>const int maxn = 505;//人的个数using namespace std;int c,d,v;struct node{ char love[10]; char hate[10];};struct edge{ int u,v,next;};edge e[maxn*1000];int head[maxn],tot;int link[maxn],vis[maxn];node man[maxn];void add(int u, int v){ e[tot].u = u; e[tot].v = v; e[tot].next = head[u]; head[u] = tot++;}int can(int u){ for(int i = head[u]; i!=-1; i=e[i].next) { int v = e[i].v; if(!vis[v]) { vis[v] = 1; if(link[v]==-1||can(link[v])) { link[v] = u; link[u] = v; return 1; } } } return 0;}int MaxMatch(){ int ret = 0; memset(link, -1,sizeof(link)); for(int i = 1; i <= v; i++) { if(link[i]!=-1)continue; memset(vis,0,sizeof(vis)); ret += can(i); } return ret;}int main(){ int t; scanf("%d",&t); while(t--) { tot = 0; memset(head, -1, sizeof(head)); scanf("%d%d%d",&c,&d,&v); for(int i = 1; i <= v; i++) { scanf("%s%s",man[i].love, man[i].hate); } for(int i = 1; i <= v; i++) { for(int j = i+1; j <= v; j++) { if(strcmp(man[i].love,man[j].hate)==0||strcmp(man[i].hate,man[j].love)==0) { add(i,j); add(j,i); } } } printf("%d\n",v-MaxMatch()); } return 0;}
0 0
- 二分匹配_HDU_2768
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 二分匹配
- 第12周 【项目3】日期时间类
- VxWorks/MIPS中断处理机制
- java小计算器
- 毕设-周报-20150520
- POJ 2533 Longest Ordered Subsequence
- 二分匹配_HDU_2768
- WMI使用的Win32类名
- 谈谈互联网公司的管理
- 用C和C++,两种方式实现C语言中的printf函数
- NET设计模式-单例模式(Singleton Pattern)
- 核反应堆问题
- leetcode Two Sum
- [leetcode][tree] Construct Binary Tree from Preorder and Inorder Traversal
- CMD命令大全