题目描述:

给出一系列男女配对意愿信息。求一个集合中的最大人数,满足这个集合中两两的人不能配对。

/*
二分图的最大独立集
因为没有给出具体的男生和女生,所以可以将数据扩大一倍,即n个男生,n个女生,
根据定理,最大独立集=总数-匹配数(本题应该除以2)
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 510
using namespace std;
int a[N][N],used[N],belong[N],n;
bool find(int i)
{
for(int j=;j<=n;j++)
if(a[i][j]&&!used[j])
{
used[j]=;
if(!belong[j]||find(belong[j]))
{
belong[j]=i;
return true;
}
}
return false;
}
void work()
{
for(int i=;i<=n;i++)
{
int x,m;scanf("%d: (%d)",&x,&m);x++;
for(int j=;j<=m;j++)
{
int y;scanf("%d",&y);y++;
a[x][y]=a[y][x]=;
}
}
int tot=;
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(find(i))tot++;
}
printf("%d\n",n-tot/);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(belong,,sizeof(belong));
work();
}
return ;
}

Girls and Boys(poj 1466)的更多相关文章

  1. Girls and Boys POJ - 1466 【(二分图最大独立集)】

    Problem DescriptionIn the second year of the university somebody started a study on the romantic rel ...

  2. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  3. poj 1466 Girls and Boys(二分图的最大独立集)

    http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submis ...

  4. poj 1466 Girls and Boys 二分图的最大匹配

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...

  5. POJ 1466 Girls and Boys (匈牙利算法 最大独立集)

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 10912   Accepted: 4887 D ...

  6. 网络流(最大独立点集):POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...

  7. poj 1466 Girls and Boys (最大独立集)

    链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...

  8. POJ 1466:Girls and Boys 二分图的最大点独立集

    Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 11097   Accepted: 4960 D ...

  9. POJ Girls and Boys (最大独立点集)

                                                                Girls and Boys Time Limit: 5000MS   Memo ...

随机推荐

  1. OAuth2.0认证和授权原理

    什么是OAuth授权?   一.什么是OAuth协议 OAuth(开放授权)是一个开放标准. 允许第三方网站在用户授权的前提下访问在用户在服务商那里存储的各种信息. 而这种授权无需将用户提供用户名和密 ...

  2. POJ3233Matrix Power Series(十大矩阵问题之三 + 二分+矩阵快速幂)

    http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total ...

  3. android加载大图片到内存

    1)演示效果: 1)代码演示: 布局代码: 权限配置:

  4. 在不借助其他工具的情况下破解Windows开机密码

    文章:http://www.cnblogs.com/vforbox/p/4828855.html#!comments. 从该文章我们也可以得到一个快速启动某个程序的方法:将自己常用的程序命名为seth ...

  5. shell中条件判断if中的-z到-d的意思

    shell中条件判断if中的-z到-d的意思 [ -a FILE ] 如果 FILE 存在则为真. [ -b FILE ] 如果 FILE 存在且是一个块特殊文件则为真. [ -c FILE ] 如果 ...

  6. Swift定义单例

    而在Swift中我们通过清晰的语法便能定义类变量: 通过static定义的类变量无法在子类重写,通过class定义的类变量则可在子类重写. struct SomeStructure { static ...

  7. Max批量导出工具

    Max批量导出工具 http://www.paulneale.com/scripts/batchItMax/batchItMax.htm Scripts Batch It Max: Batch It ...

  8. python 入门

    bool t, f = True, False print type(t) # Prints "<type 'bool'>"   字符串 hello = 'hello' ...

  9. Redis Cluster 理论知识

    http://www.ttlsa.com/redis/redis-cluster-theoretical-knowledge/ Redis 集群的 TCP 端口(Redis Cluster TCP p ...

  10. Grunt之项目脚手架

    在网上搜了下,grunt这方面的教程挺少的,来去都是一些被频繁转载的文章.唉,人艰不拆啊. 首先我们在全局环境中安装grunt-init. npm install -g grunt-init 来看看官 ...