poj 1274The Perfect Stall
第一次接触二分图匹配。
这题是一个匈牙利算法的模板题直接套即可。
题意是 给你奶牛和谷仓的个数a和b,接下来a行是奶牛喜欢去的谷仓。第一个是谷仓个数,接下来是谷仓编号。
这里我们把行当奶牛,列当谷仓。
在套模板。
。ok;
#include<Stdio.h>
#include<string.h>
int map[1005][1005];
int a,b,link[1005],use[1005]; int dfs(int cap)
{
int i,j;
for(i=1;i<=b;i++)
{
if(map[cap][i]&&!use[i])
{
use[i]=1;
j=link[i];
link[i]=cap;
if(j==-1||dfs(j))
return 1;
link[i]=j;
}
}
return 0;
} int hungary()
{
int num=0;
int i,j;
memset(link,-1,sizeof(link));
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
use[j]=0;
}
if(dfs(i))
num++;
}
return num;
}
int main()
{
int i,j,c,d;
while(~scanf("%d %d",&a,&b))
{
memset(map,0,sizeof(map));
for(i=1;i<=a;i++)
{
scanf("%d",&c);
for(j=1;j<=c;j++)
{
scanf("%d",&d);
map[i][d]=1;
}
}
printf("%d\n",hungary());
}
return 0;
}
poj 1274The Perfect Stall的更多相关文章
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- poj 1247 The Perfect Stall 裸的二分匹配,但可以用最大流来水一下
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16396 Accepted: 750 ...
- Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)
Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- poj 1274 The Perfect Stall【匈牙利算法模板题】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20874 Accepted: 942 ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- poj —— 1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26274 Accepted: 116 ...
- POJ1274 The Perfect Stall[二分图最大匹配]
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
随机推荐
- maven仓库总结,maven私服搭建
配置pom.xml依赖包时在这里找包的描述: http://search.maven.org/#browse 以java为根目录. mvn archtype:generate -DgroupId=zt ...
- html+css实现登录界面
<!DOCTYPE html> <style type="text/css"> body{ background-color: #555555; } #ti ...
- hdu 1698 Just a Hook(线段树之 成段更新)
Just a Hook Time Limit: ...
- Go by Example
Go by Example Go is an open source programming language designed for building simple, fast, and reli ...
- ECshop lib_base.php on line 1241 错误解决方法
ECSHOP做的一个网站,突然报这个错误,整个网站打不开,后来找了很久,终于找到这个方法,亲测可用 Notice: Undefinedvariable: data in D:\wwwroot\KISS ...
- cocos2d-x3.0 实现HTTP请求GET、POST
HTTP请求实现 把以下代码拷贝到新创建的project中就能看到效果 HelloWorldScene.h #include "cocos2d.h" /*记得要引头文件*/ #in ...
- DESCryptoServiceProvider加密解密的简单使用例子
DES.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- java 配置及安装Eclipse
jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for ...
- lucas定理解决大组合数取模
LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...
- WPF对于xml的简单操作(上)
private void button1_Click(object sender, RoutedEventArgs e) { XmlTextWriter writer = new XmlTextWri ...