【HDU3829】【二分匹配】【最小独立集】【问啥建啥】
2015-09-04 10:41
423 查看
Cat VS Dog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 3117 Accepted Submission(s): 1086
Problem Description
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers dislike-animal must be a dog, and vice versa.
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
Input
The input file contains multiple test cases, for each case, the first line contains three integers N <= 100, M <= 100 and P <= 500.
Next P lines, each line contains a child's like-animal and dislike-animal, C for cat and D for dog. (See sample for details)
Output
For each case, output a single integer: the maximum number of happy children.
Sample Input
1 1 2 C1 D1 D1 C1 1 2 4 C1 D1 C1 D1 C1 D2 D2 C1
Sample Output
1 3 HintCase 2: Remove D1 and D2, that makes child 1, 2, 3 happy.
Source
2011 Multi-University Training Contest 1 - Host
by HNU
Recommend
xubiao
#include <iostream> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <cstdlib> #include <cstdio> #include <algorithm> using namespace std; const int N = 550; int g ; int used ; int uN,vN; int match ; bool dfs(int u) { for(int i=1;i<=vN;i++) { if(!used[i] && g[u][i]) { used[i] = true; if(match[i] == -1 || dfs(match[i])) { match[i] = u; return true; } } } return false; } int hungary() { int ret = 0; for(int i=1;i<=uN;i++) { memset(used,0,sizeof(used)); if(dfs(i)) ret++; } return ret; } int n,m,p; struct Node { char s1[5],s2[5]; void input() { scanf("%s%s",s1,s2); } }node[550]; int main() { while(scanf("%d%d%d",&n,&m,&p)!=EOF) { memset(match,-1,sizeof(match)); memset(g,0,sizeof(g)); for(int i=1;i<=p;i++) { node[i].input(); } for(int i=1;i<=p;i++) { for(int j=1;j<=p;j++) { if(strcmp(node[i].s1,node[j].s2) == 0 || strcmp(node[i].s2,node[j].s1) == 0) { g[i][j] = 1; g[j][i] = 1; } } } vN = p; uN = p; printf("%d\n",p-hungary()/2); } return 0; }
相关文章推荐
- ViewPager 基本方式加载view
- 老毛桃u盘启动盘制作工具怎么用及重装系统步骤(一)
- Android之TabHost用法—定义Tab标签样式
- Windows Socket 编程_ 简单的服务器/客户端程序
- 安全软件启动先导保护-各模块流程图[待完善]
- C++11 类的六个默认函数及其使用
- 求一段字符串中出现的相同且长度最长的字符串
- C++11 类的六个默认函数及其使用
- 2015 九月份学习记录
- python挑战题(转+个人解答)
- SQL删除重复数据方法
- TQ2440 学习笔记—— 27、移植U-Boot【Bootloader 作用、工作流程】
- Hudson 执行shell脚本(Hudson 启动Tomcat 无效问题)
- makefile相同目标的合并之问题
- 什么是堆和栈,它们在哪儿?
- 设计模式之简单工厂模式
- 工具篇——轻松使用Fiddler抓包(For Android)
- UVA11090 Going in Cycle (二分+判负环)
- [lintcode][美国大公司][1.字符串处理]
- 小白学习iOS开发都需要有什么基础