poj 1274 The Perfect Stall【匈牙利算法模板题】
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 20874 | Accepted: 9421 |
Description
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible.
Input
Output
Sample Input
5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2
Sample Output
4 题意:奶牛只在指定的摊位才肯产奶,第一行输入n,m分别代表母牛数量和摊位的数量,接下来m行,第i行就代表第i头奶牛,每行开头一个数k代表接下来这一行要输入的摊位号 匈牙利算法模板都快忘了 复习一下 以后也不能老刷模板题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 210
using namespace std;
int n,m;
int cow[MAX][MAX],space[MAX];
int vis[MAX];
int find(int x)
{
int i,j;
for(i=1;i<=m;i++)
{
if(cow[x][i]&&!vis[i])
{
vis[i]=1;
if(space[i]==0||find(space[i]))
{
space[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,t,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(cow,0,sizeof(cow));
memset(space,0,sizeof(space));
for(i=1;i<=n;i++)
{
scanf("%d",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&a);
cow[i][a]=1;
}
}
int sum=0;
for(i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
printf("%d\n",sum);
}
return 0;
}
poj 1274 The Perfect Stall【匈牙利算法模板题】的更多相关文章
- POJ 1325 && 1274:Machine Schedule 匈牙利算法模板题
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12976 Accepted: 5529 ...
- 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 解题报告
题目链接:http://poj.org/problem?id=1274 题目意思:有 n 头牛,m个stall,每头牛有它钟爱的一些stall,也就是几头牛有可能会钟爱同一个stall,问牛与 sta ...
- POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)
嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- POJ 3041 匈牙利算法模板题
一开始预习是百度的算法 然后学习了一下 然后找到了学长的ppt 又学习了一下.. 发现..居然不一样... 找了模板题试了试..百度的不好用 反正就是wa了..果然还是应当跟着学长混.. 图两边的点分 ...
随机推荐
- 【Asp.Net】小BUG汇总[更新]
目录结构 1.Dictionary<T>遍历 2.Asp.net网站部署在C盘无法上传下载文件 3.Asp.Net网站发布后远程无法访问 4.GDI+中发生一般性错误 1.Dictiona ...
- Function Pointer in Delpni
program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TVoice = function(): Stri ...
- sublimeformaya
网上没有找到这样的插件自己造了一个 https://github.com/jonntd/connectionmaya 附件列表
- linq any()方法实现sql in()方法的效果
public IQueryable<Vsec009ComSecComp> QueryList(Sec009ComSecCompQueryCondition condition) { var ...
- 导航 - 利用系统自带的App导航
导航: 可以将需要导航位置丢给系统自带的App进行导航 发送网络请求到公司服务器, 获取导航数据, 自己手动绘制导航 利用三方SDK进行导航(百度) #import "ViewControl ...
- Intellij IDEA快速编写代码经验总结
sout=System.out.println(); soutp=System.out.println(""); soutv=System.out.println("变量 ...
- VC下载文件 + 显示进度条
在codeproject里找了许久,发现这样一个VC下载文件并显示进度条的源码,于是添加了些中文注释: 1.下载线程函数: UINT DownloadFile(LPVOID pParam) { CWn ...
- iframe的安全问题
今天尝试在iframe中嵌入外部网站, 碰到了一些小问题. 如何让自己的网站不被其他网站的iframe引用? 我测试的时候发现我把iframe的src指定到github不起作用. 原来是它把X-Fra ...
- 转:三十三、Java图形化界面设计——布局管理器之null布局(空布局)——即SWT中的绝对布局
http://blog.csdn.net/liujun13579/article/details/7774267 一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到 ...
- java学习多线程之卖票示例
这一节我们来说一个示例就是卖票示例: 需求: 我们现在有100张票,然后分四个窗口来卖,直到卖完为止. 思路: 1.先定一个一个票类,描述票的属性,还有打印卖出的票,并且实现Runnable中的run ...