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. 

InputThe 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) 
OutputFor 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

Hint

Case 2: Remove D1 and D2, that makes child 1, 2, 3 happy.
题意:动物园有猫和狗,一个孩子有喜欢和不喜欢的动物,喜欢猫就一定讨厌狗,反之亦然,现可拿走动物使孩子最高兴
题解:最大独立集,二分图的最大独立集=顶点数-二分图最大匹配,接下来就是建图,把孩子当作点,如果某个孩子喜欢的动物是另一个讨厌的,那么就连边
我们希望减少最小的孩子数来满足所有人的喜好,这就是最小点覆盖。
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=0x3f3f3f3f; int n,m,p,color[N];
bool used[N],ok[N][N];
struct edge{
string a,b;
}e[N]; bool match(int x)
{
for(int i=;i<=p;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(color[i]==-||match(color[i]))
{
color[i]=x;
return ;
}
}
}
return ;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
while(cin>>n>>m>>p){
memset(ok,,sizeof ok);
for(int i=;i<=p;i++)
{
cin>>e[i].a>>e[i].b;
e[i].id=i;
}
for(int i=;i<=p;i++)
for(int j=;j<=p;j++)
if(e[i].a==e[j].b||e[i].b==e[j].a)
ok[i][j]=ok[j][i]=;
/* for(int i=1;i<=p;i++)
{
for(int j=1;j<=p;j++)
cout<<ok[i][j];
cout<<endl;
}*/
int ans=;
memset(color,-,sizeof color);
for(int i=;i<=p;i++)
{
memset(used,,sizeof used);
ans+=match(i);
}
cout<<p-ans/<<endl;
}
return ;
}

hdu3829最大独立集的更多相关文章

  1. hdu3829(最大独立集)

    传送门:Cat VS Dog 题意:动物园有N只猫,M只狗,P个小孩.每个小孩都有自己喜欢的动物和讨厌的动物,如果他喜欢狗,那么就讨厌猫, 如果他讨厌狗,那么他就喜欢猫.某个小孩能开心,当且仅当他喜欢 ...

  2. HDU3829(KB10-J 二分图最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  3. HDU3829:Cat VS Dog(最大独立集)

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  4. HDU3829 Cat VS Dog —— 最大独立集

    题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. hdu3829 二分匹配 最大独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...

  6. HDU3829 Cat VS Dog

    题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...

  7. poj 3692 Kindergarten (最大独立集)

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4903   Accepted: 2387 Desc ...

  8. 【BZOJ-4316】小C的独立集 仙人掌DP + 最大独立集

    4316: 小C的独立集 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 57  Solved: 41[Submit][Status][Discuss] ...

  9. loj 1201(最大独立集)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26913 思路:水题一枚,就是求最大独立集.最大独立集=顶点数-最大 ...

随机推荐

  1. Bug跟踪的流程

    本文以翼发云协同项目管理系统为例子来讲解Bug跟踪的流程,它以工作流为中心的集成式Bug跟踪软件,它广泛地应用于研发行业的产品缺陷管理 与跟踪.事务跟踪.问题跟踪.任务跟踪.查询跟踪.需求管理.变更跟 ...

  2. Windows Phone 8.1开发:触控和指针事件2

    原文出自:http://www.bcmeng.com/windows-phone-touch1/ 请在此输入内容(想死啊,写了一个小时,直接没保存不小心删掉了.那就简单说说吧)Pointer事件有以下 ...

  3. MCMC(一)蒙特卡罗方法

    MCMC(一)蒙特卡罗方法 MCMC(二)马尔科夫链(待填坑) MCMC(三)M-H采样和Gibbs采样(待填坑) 作为一种随机采样方法,马尔科夫链蒙特卡罗(Markov Chain Monte Ca ...

  4. linux 下的 mkfifo、exec 命令使用

    MKFIFOSection: User Commands (1)Updated: 1998年11月Index Return to Main Contents  NAME(名称)mkfifo - 创建F ...

  5. 机器学习:Python中如何使用最小二乘法

    之所以说"使用"而不是"实现",是因为python的相关类库已经帮我们实现了具体算法,而我们只要学会使用就可以了.随着对技术的逐渐掌握及积累,当类库中的算法已经 ...

  6. 手机自动化测试:appium源码分析之bootstrap十七

    手机自动化测试:appium源码分析之bootstrap十七   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  7. 性能调优:mysql之left join

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...

  8. 不可不知的 Android strings.xml 那些事

    相信 strings.xml 已经是大家在 Android 开发中最熟悉的文件之一了,但其实它也有很多需要注意的地方和一些小技巧,知道了这些可以让你的 Android 应用更加规范易用,大家来看看吧. ...

  9. MYSQL数据库导入大数据量sql文件失败的解决方案

    1.在讨论这个问题之前首先介绍一下什么是"大数据量sql文件". 导出sql文件.选择数据库-----右击选择"转储SQL文件"-----选择"结构和 ...

  10. Html 经典布局(三)

    经典布局案例(三): <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...