poj1274:http://poj.org/problem?id=1274

题意:有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶牛能够吃到东西

题解:裸的二分图匹配,直接上匈牙利。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=;
int n,m,k,w,u,v;
int cy[MAXN];
bool visit[MAXN];
bool g[MAXN][MAXN];
int path(int u){
for(int i=;i<=m;i++){
if(!visit[i]&&g[u][i]){
visit[i]=;
if(cy[i]==-||path(cy[i])){
cy[i]=u;
return ;
}
}
}
return ;
}
int maxmatch(){
memset(cy,-,sizeof(cy));
int res=;
for(int i=;i<=n;i++){
memset(visit,,sizeof(visit));
res+=path(i);
}
return res;
}
int main(){
while(~scanf("%d%d",&n,&m)&&n){
memset(g,,sizeof(g));
for(int i=;i<=n;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&w);
g[i][w]=;
} }
printf("%d\n",maxmatch());
}
}

The Perfect Stall的更多相关文章

  1. POJ1274 The Perfect Stall[二分图最大匹配]

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23911   Accepted: 106 ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. poj 1247 The Perfect Stall 裸的二分匹配,但可以用最大流来水一下

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16396   Accepted: 750 ...

  4. poj 1274 The Perfect Stall【匈牙利算法模板题】

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20874   Accepted: 942 ...

  5. USACO Section 4.2 The Perfect Stall(二分图匹配)

    二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...

  6. POJ1274_The Perfect Stall(二部图最大匹配)

    解决报告 http://blog.csdn.net/juncoder/article/details/38136193 id=1274">题目传送门 题意: n头m个机器,求最大匹配. ...

  7. USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)

    The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...

  8. usaco training 4.2.2 The Perfect Stall 最佳牛栏 题解

    The Perfect Stall题解 Hal Burch Farmer John completed his new barn just last week, complete with all t ...

  9. 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 农夫约翰上个 ...

  10. POJ1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25739   Accepted: 114 ...

随机推荐

  1. GUI编程笔记(java)08:GUI通过鼠标移动到按钮上更改背景色案例

    首先我们看看源代码如下: package cn.itcast_06; import java.awt.Button; import java.awt.Color; import java.awt.Fl ...

  2. Linux Shell删除某一个目录下的所有文件夹(保留其他文件)

    #!/bin/bash direc=$(pwd) for dir2del in $direc/* ; do if [ -d $dir2del ]; then rm -rf $dir2del fi do ...

  3. Powerdesigner中如何生成测试数据

    设计表完成以后,我们需要生成一些测试数据,可以直接更新到数据库中,下面我们就来试试: 第一步:建立需要的Profiles测试文件,[Model]--[Test Data Profiles],如图所示: ...

  4. SharePoint Dialog 使用

    SharePoint中弹出模态窗口对体验提高太大了 方法为: 父页面中调用子页面: function showDialog() {        var options = {             ...

  5. CentOS&nbsp;6.4&nbsp;图文安装教…

    点评:CentOS 6.4是最新的出的系统,这里分享下安装教程,有些设置大部分教程没出现过,特分享下,方便需要的朋友 CentOS 6.4 下载地址: http://www.jb51.net/soft ...

  6. JS2 for应用

    for应用  再谈js获取元素一二: var oUl=document.getElementById('list');      //静态方法 var oUl=document.getElements ...

  7. java web 中的转发和重定向

    假设应用程序的 contextPath 为 /ctx,在 http://localhost:8080/ctx/a/b 资源中,我们转发和重定向到 http://localhost:8080/ctx/x ...

  8. html 包含一个公共文件

    <SCRIPT> $(document).ready(function(){ $("#foo").load("top.html"); setTime ...

  9. 日文“表” php 会报错

    php遇到很奇怪的问题,文字“表”会报错,并且是属于编译错误的问题. 单纯的输出: echo " 表 "; 会直接报错. 可是只要在中间加点东西,就可以解决这个问题,就算是空格都可 ...

  10. JAVA 循环在一个数字前面填充0.小例子

    输入结果 00000000000567 String bala="567"; 固定长度是14位,怎么循环在bala前面填充00000000000 System.out.printl ...