O - Steady Cow Assignment - POJ 3189(多重匹配+枚举)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ;
const int MAXM = ; int G[MAXN][MAXM], N, M;
int cows[MAXM];///牛棚最多可以安放的牛的数量
bool used[MAXM];
struct Link{int link[MAXN], len;}Ly[MAXM]; bool Find(int i, int L, int R)
{
for(int j=; j<=M; j++)
{
if( G[i][j]>=L && G[i][j]<=R && !used[j] )
{
used[j] = true; if( Ly[j].len < cows[j] )
{
Ly[j].link[ Ly[j].len++ ] = i;
return true;
}
for(int k=; k<Ly[j].len; k++)
{
if( Find( Ly[j].link[k], L, R ) == true )
{
Ly[j].link[k] = i;
return true;
}
}
}
} return false;
}
bool XYL(int L, int R)
{
memset(Ly, false, sizeof(Ly)); for(int i=; i<=N; i++)
{
memset(used, false, sizeof(used));
if( Find(i, L, R) == false )
return false;
} return true;
} int main()
{
while(scanf("%d%d", &N, &M) != EOF)
{
int i, j, L=, R=M, Mid, ans, v; for(i=; i<=N; i++)
for(j=; j<=M; j++)
{
scanf("%d", &v);
G[i][v] = j;
} for(i=; i<=M; i++)
scanf("%d", &cows[i]); while(L <= R)
{
Mid = (L+R) >> ; for(i=; i<=M; i++)
{
if( XYL(i, i+Mid) == true )
break;
} if(i <= M)
R = Mid-, ans = Mid;
else
L = Mid+;
} printf("%d\n", ans+);
} return ;
}
O - Steady Cow Assignment - POJ 3189(多重匹配+枚举)的更多相关文章
- Steady Cow Assignment POJ - 3189 (最大流+匹配)
Farmer John's N (1 <= N <= 1000) cows each reside in one of B (1 <= B <= 20) barns which ...
- POJ 3189——Steady Cow Assignment——————【多重匹配、二分枚举区间长度】
Steady Cow Assignment Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- Poj 3189 Steady Cow Assignment (多重匹配)
题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...
- POJ3189:Steady Cow Assignment(二分+二分图多重匹配)
Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7482 Accepted: ...
- POJ3189 Steady Cow Assignment —— 二分图多重匹配/最大流 + 二分
题目链接:https://vjudge.net/problem/POJ-3189 Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65 ...
- POJ 2289 Jamie's Contact Groups & POJ3189 Steady Cow Assignment
这两道题目都是多重二分匹配+枚举的做法,或者可以用网络流,实际上二分匹配也就实质是网络流,通过枚举区间,然后建立相应的图,判断该区间是否符合要求,并进一步缩小范围,直到求出解.不同之处在对是否满足条件 ...
- POJ3189 Steady Cow Assignment
Steady Cow Assignment Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6817 Accepted: ...
- POJ 3189 Steady Cow Assignment 【二分】+【多重匹配】
<题目链接> 题目大意: 有n头牛,m个牛棚,每个牛棚都有一定的容量(就是最多能装多少只牛),然后每只牛对每个牛棚的喜好度不同(就是所有牛圈在每个牛心中都有一个排名),然后要求所有的牛都进 ...
- POJ 3189 Steady Cow Assignment
题意:每个奶牛对所有的牛棚有个排名(根据喜欢程度排的),每个牛棚能够入住的牛的数量有个上限,重新给牛分配牛棚,使牛棚在牛心中的排名差(所有牛中最大排名和最小排名之差)最小. 题目输入: 首先是两个 ...
随机推荐
- Android 环境下编译FFmpeg
Android 环境下编译FFmpeg 开发环境:Ubuntu 12.04.2 LTS , android-sdk-linux, android-ndk-r8e 一 .X264 编译 1. X2 ...
- codevs 1200 同余方程 (Extend_Eulid)
/* 扩展欧几里得 ax%b==1 -> ax-by==1 求不定方程的一组解 使x为最小正整数解 */ #include<iostream> #include<cstdio& ...
- windows服务(Windows Installer问题,错误5:拒绝访问)
Windows Installer问题,错误5:拒绝访问 shillan,2006-11-03 09:40:38 现象: 使用MSI文件来安装的软件在安装和卸载时系统提示:“不能访问Windows I ...
- MySQL+PHP配置 Windows系统IIS版(转)
1.下载 MySQL下载地址:http://dev.mysql.com/downloads/mysql/5.1.html->Windows (x86, 32-bit), MSI Installe ...
- 织梦DeDeCms列表分页和内容页分页错位解决办法
文章页分页代码在这里/include/arc.archives.class.php列表页分页/include/arc.listview.class.php 很多入门的站长会碰到这样的问题,织梦的通病, ...
- CSS 让标点符号不出现在行首
word-break:break-all; 这条语句的作用是让语句到达边界的时候自动换行,但是正是这个样式让标点符号跑到了行首. 语法: word-break : normal | break-all ...
- .net 计算当前时间距离今晚00:00:00还有多少分多少秒
string dateDiff = null; DateTime DateTime1 = DateTime.Now; //第二天的0点00分00秒 DateTime DateTime2 = DateT ...
- DHCP服务器
DHCP指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码.首先,DHCP服务器必须是一台安装有Windows 2000 Server/Advanced ...
- this,super关键字的使用
this关键字 1.this是对象的别名,是当前类的实例引用 2.在类的成员方法内部使用,代替当前类的实例.在Java中,本质上是指针,相当于C++中的指针概念.如果方法中的成员在调用前没有操作实例名 ...
- gis-矢量与栅格数据结构的比较
2.5矢量与栅格数据结构的比较 在计算机辅助制图和地理信息系统发展早期,最初引用的是矢量处理技术,栅格数据处理始于70年 代中期.几年以前,这两种数据结构势不两立,很难兼容,因此给数据利用带来许多不便 ...