【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)
Less Time, More profit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Each shop needs products from some plants to make profit of proi units.
Building ith plant needs investment of payi units and it takes ti days.
Two or more plants can be built simultaneously, so that the time for building multiple plants is maximum of their periods(ti).
You should make a plan to make profit of at least L units in the shortest period.
For each test case, there are three integers N, M, L described above.
And there are N lines and each line contains two integers payi, ti(1<= i <= N).
Last there are M lines and for each line, first integer is proi, and there is an integer k and next k integers are index of plants which can produce material to make profit for the shop.
1 <= T <= 30
1 <= N, M <= 200
1≤L,ti≤1000000000
1≤payi,proi≤30000
Output
If this plan is impossible, you should print “Case #x: impossible”
Sample Input
Sample Output
Author
M个商店,N个工厂,每个商店获利的条件是建设了指定的k个工厂。求总获利不小于L,工厂建设的时间最大值最小是多少。
工厂到汇点建一条边pay[i],源点到商店建一条边pro[i],商店到需要的工厂建一条边INF,商店的总收益-最小割就是答案。
可以看看国家集训队论文:Amber《最小割模型在信息学竞赛中的应用》
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#define N 205<<1
#define sf(a) scanf("%d",&a);
using namespace std;
const int INF=0x3f3f3f3f;
struct plant{
int pay,t,id;
}pt[N];
struct shop{
int pro,k,pt[N],t;
}s[N];
int t,n,m,l,st,ed,tot;
int arc[N][N], d[N];
int ans,tans;
bool bfs()
{
memset(d, -, sizeof d);
queue<int>q;
q.push(st);
d[st] = ;
while(!q.empty())
{
int i,k=q.front();
q.pop();
for(i = ; i <= ed; i++)
if(arc[k][i] > && d[i] == -)
{
d[i] = d[k] + ;
q.push(i);
}
}
return d[ed]>;
}
int dinic (int k, int low)
{
if(k == ed)return low;
int a,i;
for(i = ; i <= ed; i++)
if(d[i] == d[k] + && arc[k][i] > &&(a = dinic(i, min(low, arc[k][i]))))
{
arc[k][i] -= a;
arc[i][k] += a;
return a;
}
return ;
}
int cmp(plant a,plant b){
return a.t<b.t;
}
int main() {
sf(t);
for(int cas=;cas<=t;cas++){
printf("Case #%d: ",cas);
scanf("%d%d%d",&n,&m,&l);
for(int i=;i<=n;i++){
scanf("%d%d",&pt[i].pay,&pt[i].t);
pt[i].id=i;
}
for(int i=;i<=m;i++){
sf(s[i].pro);
sf(s[i].k);
s[i].t=;
for(int j=;j<=s[i].k;j++){
int x;
sf(x);
s[i].pt[j]=x;
s[i].t=max(s[i].t,pt[x].t);
}
}
sort(pt+,pt++n,cmp);
int ok=;
st=n+m+,ed=st+;
for(int i=;i<=n;i++){
memset(arc,,sizeof arc);
for(int j=;j<=i;j++)
arc[pt[j].id][ed]=pt[j].pay;
tot=;
for(int j=;j<=m;j++)if(s[j].t<=pt[i].t){
tot+=s[j].pro;
arc[st][j+n]=s[j].pro;
for(int k=;k<=s[j].k;k++)
arc[j+n][s[j].pt[k]]=INF;
}
ans = ;
while(bfs())
while(tans=dinic(st, INF)) ans += tans;
ans=tot-ans;
if(ans>=l){
printf("%d %d\n",pt[i].t,ans);
ok=;
break;
}
}
if(!ok)puts("impossible");
}
}
工厂按时间排序再依次增大最大时间,这样是140ms,改成二分以为会更快,结果960ms,去了注释们再交一次居然超时了。可能是dinic用的是邻接矩阵的原因。
【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)的更多相关文章
- 【POJ 2987】Firing (最小割-最大权闭合子图)
裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...
- 洛谷 - P1361 - 小M的作物 - 最小割 - 最大权闭合子图
第一次做最小割,不是很理解. https://www.luogu.org/problemnew/show/P1361 要把东西分进两类里,好像可以应用最小割的模板,其中一类A作为源点,另一类B作为汇点 ...
- [模拟赛FJOI Easy Round #2][T3 skill] (最小割+最大权闭合子图(文理分科模型))
[题目描述] 天上红绯在游戏中扮演敏剑,对于高攻击低防御的职业来说,爆发力显得非常重要,为此,她准备学习n个技能,每个技能都有2个学习方向:物理攻击和魔法攻击.对于第i个技能,如果选择物理攻击方向,会 ...
- [BZOJ1565][NOI2009]植物大战僵尸-[网络流-最小割+最大点权闭合子图+拓扑排序]
Description 传送门 Solution em本题知识点是用网络流求最大点权闭合子图. 闭合图定义:图中任何一个点u,若有边u->v,则v必定也在图中. 建图:运用最小割思想,将S向点权 ...
- BZOJ.1497.[NOI2006]最大获利(最小割 最大权闭合子图Dinic)
题目链接 //裸最大权闭合子图... #include<cstdio> #include<cctype> #include<algorithm> #define g ...
- Petya and Graph(最小割,最大权闭合子图)
Petya and Graph http://codeforces.com/contest/1082/problem/G time limit per test 2 seconds memory li ...
- hihocoder1398 网络流五之最大权闭合子图
最大权闭合子图 虽然我自己现在总结不好最大权闭合子图.但也算稍稍理解辣. 网络流起步ing~~~(- ̄▽ ̄)- #include<iostream> #include<cstdio& ...
- HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】
Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...
- 【hdu 4859】海岸线(图论--网络流最小割)
题意:有一个区域,有'.'的陆地,'D'的深海域,'E'的浅海域.其中浅海域可以填充为陆地.这里的陆地区域不联通,并且整个地图都处在海洋之中.问填充一定浅海域之后所有岛屿的最长的海岸线之和. 解法:最 ...
- HDU 3917 Road constructions(最小割---最大权闭合)
题目地址:HDU 3917 这题简直神题意... 题目本身就非常难看懂不说..即使看懂了.也对这题意的逻辑感到无语...无论了.. 就依照那题意上说的做吧... 题意:给你n个城市,m个公司.若干条可 ...
随机推荐
- android gridview画分割线,如图:
1.先上图: 2.具体实现代码: public class LineGridView extends GridView { public LineGridView(Context context) { ...
- grunt-contrib-uglify压缩插件的常用配置属性
mangle:false(不混淆变量名和方法名,保留原有的名字),如果不配置,默认混淆,就是将所有方法名和变量都用a,b,c等字母替换 preserveComments : 'all'(不删除注释,还 ...
- C# 内存信息
Process proc = Process.GetCurrentProcess(); Console.Write("专用工作集内存:"); ...
- PAT 1002. 写出这个数 (20)
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字之和的每 ...
- [转]使用 google gson 转换Timestamp或Date类型为JSON字符串.
创建类型适配类: import java.lang.reflect.Type; import java.sql.Timestamp; import java.text.DateFormat; impo ...
- Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法
1.必须用Chrome打开 2.在mac电脑上,可能Chrome打开也是空白,解决办法是:在chrome地址栏中输入”chrome:tracing”,然后点击load按钮load你的trace.htm ...
- BatsingJSLib 2.3、Ajax上传多个文件
//2.3Ajax上传单个或多个文件 //<input type="file" multiple="multiple"/> //参数:文件的表单JD ...
- 为 Xamarin.Forms 做个跑马灯控件
前段时间,私下用 Xamarin.Forms 做了个商业项目的演示版.很多被国内App玩坏了的控件/效果,XF上都没有或是找不到对应的实现,没有办法只能亲自上阵写了几个,效果还行,就是有BUG. 这个 ...
- spring boot 自动部署方案
现在主流的自动部署方案大都是基于Docker的了,但传统的自动部署方案比较适合中小型公司,下面的方案就是比较传统的自动部署方案. 1.为什么需要自动部署 基于微服务的架构,自动部署显得非常重要.因为每 ...
- How to remove a batch of VMs and related Disks
Foreword Need to remove a batch of VMs, which named with same prefix or belong to same Cloud Service ...