Less Time, More profit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
The city planners plan to build N plants in the city which has M shops.

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.

 
Input
First line contains T, a number of test cases.

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

For each test case, first line contains a line “Case #x: t p”, x is the number of the case, t is the shortest period and p is maximum profit in t hours. You should minimize t first and then maximize p.

If this plan is impossible, you should print “Case #x: impossible”

 

Sample Input

2
1 1 2
1 5
3 1 1
 
1 1 3
1 5
3 1 1
 

Sample Output

Case #1: 5 2
Case #2: impossible
 

Author

金策工业综合大学(DPRK)
  
Source

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(网络流、最小割、最大权闭合子图)的更多相关文章

  1. 【POJ 2987】Firing (最小割-最大权闭合子图)

    裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...

  2. 洛谷 - P1361 - 小M的作物 - 最小割 - 最大权闭合子图

    第一次做最小割,不是很理解. https://www.luogu.org/problemnew/show/P1361 要把东西分进两类里,好像可以应用最小割的模板,其中一类A作为源点,另一类B作为汇点 ...

  3. [模拟赛FJOI Easy Round #2][T3 skill] (最小割+最大权闭合子图(文理分科模型))

    [题目描述] 天上红绯在游戏中扮演敏剑,对于高攻击低防御的职业来说,爆发力显得非常重要,为此,她准备学习n个技能,每个技能都有2个学习方向:物理攻击和魔法攻击.对于第i个技能,如果选择物理攻击方向,会 ...

  4. [BZOJ1565][NOI2009]植物大战僵尸-[网络流-最小割+最大点权闭合子图+拓扑排序]

    Description 传送门 Solution em本题知识点是用网络流求最大点权闭合子图. 闭合图定义:图中任何一个点u,若有边u->v,则v必定也在图中. 建图:运用最小割思想,将S向点权 ...

  5. BZOJ.1497.[NOI2006]最大获利(最小割 最大权闭合子图Dinic)

    题目链接 //裸最大权闭合子图... #include<cstdio> #include<cctype> #include<algorithm> #define g ...

  6. Petya and Graph(最小割,最大权闭合子图)

    Petya and Graph http://codeforces.com/contest/1082/problem/G time limit per test 2 seconds memory li ...

  7. hihocoder1398 网络流五之最大权闭合子图

    最大权闭合子图 虽然我自己现在总结不好最大权闭合子图.但也算稍稍理解辣. 网络流起步ing~~~(- ̄▽ ̄)- #include<iostream> #include<cstdio& ...

  8. 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 ...

  9. 【hdu 4859】海岸线(图论--网络流最小割)

    题意:有一个区域,有'.'的陆地,'D'的深海域,'E'的浅海域.其中浅海域可以填充为陆地.这里的陆地区域不联通,并且整个地图都处在海洋之中.问填充一定浅海域之后所有岛屿的最长的海岸线之和. 解法:最 ...

  10. HDU 3917 Road constructions(最小割---最大权闭合)

    题目地址:HDU 3917 这题简直神题意... 题目本身就非常难看懂不说..即使看懂了.也对这题意的逻辑感到无语...无论了.. 就依照那题意上说的做吧... 题意:给你n个城市,m个公司.若干条可 ...

随机推荐

  1. vijos1334 NASA的食物计划(二维费用的背包问题)

    背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安 全技术问题一直大伤脑筋,因此在各方压力下终止了航天 飞机的历史,但是此类事情会不会在以后发生,谁也无法 保证,在遇到这类航天问题时,解决方 ...

  2. header

    本文分享几个php header函数的例子,有需要的朋友参考学习下. 转自:http://www.jbxue.com/article/php_header_x5hV63c.html 1,可以使用hed ...

  3. [Azure] 使用 Visual Studio 2013 管理中国版 Azure 订阅

    比较关心微软平台技术的朋友应该都知道,微软云服务(Microsoft Azure)以下简称Azure分为全球版和中国版,由于政府法规问题中国版的服务是由二十一世纪互联运营,整体来看中国版Azure和全 ...

  4. YII框架概念与安装

    Yii概念: YII安装:      下载最版本http://www.framework.com      解压至访问目录下 直接打开advanced/init.bat文件输入0之后输入yes 打不开 ...

  5. echo使用说明,参数详解

    简介 echo [OPTION]... [STRING]... 描述 -n 末尾不加换行 -e 开启输出字串中对反斜杠的转译 -E 禁用反斜杠转译 只有开启-e参数的时候,下面的命令才能起作用: \0 ...

  6. JavaScript中正则表达式test()、exec()、match() 方法区别

    1.test test 返回 Boolean,查找对应的字符串中是否存在模式.var str = "1a1b1c";var reg = new RegExp("1.&qu ...

  7. 工作随笔——一次简单的Maven加速构建实战

    注意:所有的编译.打包.部署全部是通过Jenkins完成的. 公司内部有一个项目,开始做的时候已经预计到会有很多客服端.所以开发就搞了如下的结构: fft-api # 公用的API,所有的程序都必须使 ...

  8. Jenkins进阶系列之——18Jenkins语言本地化

    在Jenkins中,英语一大片,看着各种蛋疼.非常高兴的是,Jenkins作为一个主流流行的持续构建工具,提供了一个本地化语言的配置界面. 你可以找到它,在Jenkins每页的左下角.如下图: 点击帮 ...

  9. Web Api通过Route、RoutePrefix等特性设置路由

    [Route("customers/{customerId}/orders")] [HttpGet] public IEnumerable<Order> FindOrd ...

  10. C语言文件的读写

    对文件的读和写是最常用的文件操作.在C语言中提供了多种文件读写的函数: 字符读写函数  :fgetc和fputc 字符串读写函数:fgets和fputs 数据块读写函数:freed和fwrite 格式 ...