hdu3829最大独立集
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最大独立集的更多相关文章
- hdu3829(最大独立集)
传送门:Cat VS Dog 题意:动物园有N只猫,M只狗,P个小孩.每个小孩都有自己喜欢的动物和讨厌的动物,如果他喜欢狗,那么就讨厌猫, 如果他讨厌狗,那么他就喜欢猫.某个小孩能开心,当且仅当他喜欢 ...
- HDU3829(KB10-J 二分图最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- HDU3829:Cat VS Dog(最大独立集)
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- HDU3829 Cat VS Dog —— 最大独立集
题目链接:https://vjudge.net/problem/HDU-3829 Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu3829 二分匹配 最大独立集
Cat VS Dog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Problem ...
- HDU3829 Cat VS Dog
题目链接:https://vjudge.net/problem/HDU-3829 题目大意: 有\(P\)个小孩,\(N\)只猫,\(M\)只狗.每个小孩都有自己喜欢的某一只宠物和讨厌的某一只宠物(其 ...
- poj 3692 Kindergarten (最大独立集)
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4903 Accepted: 2387 Desc ...
- 【BZOJ-4316】小C的独立集 仙人掌DP + 最大独立集
4316: 小C的独立集 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 57 Solved: 41[Submit][Status][Discuss] ...
- loj 1201(最大独立集)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26913 思路:水题一枚,就是求最大独立集.最大独立集=顶点数-最大 ...
随机推荐
- .NET中可空值类型实现原理
为了让.Net中的值类型可以赋值为null,微软特地添加了Nullable<T>类型,也可简写为T?.但是Nullable<T>自身是结构体,也是值类型,那么它是如何实现将nu ...
- bootstrap IE8 兼容性处理
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- benchmark 库
性能测试的库 https://github.com/bestiejs/benchmark.js
- Frame框架
框架 frameset 框架集 如果使用框架集,当前页面不能有body cols="300,*" :左右拆分,左边宽300,右边宽剩余 rows=" ...
- TCP/IP、HTTP、Socke、UDP的区别
一.TCP/IP.Http.Socket的区别 [http://jingyan.baidu.com/article/08b6a591e07ecc14a80922f1.html](http://jing ...
- 老李分享:为何要使用 Web Services
老李分享:为何要使用 Web Services poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询q ...
- 原生js实现tab切换
//通过原生js实现table切换<html><head><meta http-equiv="Content-Type" content=" ...
- 在阿里云Linux服务器上安装MySQL
申请阿里云Linux服务器 昨天在阿里云申请了一个免费试用5天的Linux云服务器. 操作系统:Red Hat Enterprise Linux Server 5.4 64位. CPU:1核 内存:5 ...
- __init__.py
python中的Module是比较重要的概念.常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时,将事先写好的.py文件拷贝 到当前目录,或者是在sys.path中增加事先写好的 ...
- 找到一个新的超好用的U盘启动制作工具了
有同事叫帮装电脑,弄个U盘说制作一个启动盘,结果一搜,出了“雨林木风”的主页. 太好用了,高手的产物,比以前找的方便一百倍.又简单,又实用,同步又下载好GHO文件.唯一 的问题是XP中用的GHO,好多 ...