【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个公司.若干条可 ...
随机推荐
- java 26 - 9 网络编程之 TCP协议多用户上传文件
TCP实现多用户上传文件: 需要同时给多用户上传文件,这样就得用多线程来实现. 实际上,这样的话,上传的先后顺序和速度就跟客户端的带宽有关:带宽够,就容易抢占到线程的执行权: 首先,创建个线程类:(这 ...
- 转: Eclipse使用SVN
评注: 很细节的说明了,svn与eclipse的使用. Eclipse使用SVN 收藏 老黎 发表于 5年前 阅读 35124 收藏 12 点赞 3 评论 6 SVN的功能再多,如果不能有效的 ...
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- sql server 修改表结构语法大全
1.增加字段 ) 2.删除字段 alter table table_name drop column column_name 3.修改字段类型 alter table table_name alter ...
- jquery的ready方法(DOM是否加载完)详解与使用
jquery的ready方法(准备DOM触发)还是比较复杂的,我们先看流程图:
- javascript中的链表结构
1.定义 很多编程语言中数组的长度是固定的,就是定义数组的时候需要定义数组的长度,所以当数组已经被数据填满的时候,需要再加入新的元素就很困难.只能说在部分变成语言中会有这种情况,在javascript ...
- 启动Oracle
[oracle@redhat ~]$ su - oracle --“切换到oracle用户”Password:[oracle@redha ...
- Java核心技术点之内部类
1. 为什么要使用内部类 内部类就是定义在一个类内部的类,那么为什么要使用内部类呢?主要原因有以下几点:第一,内部类中定义的方法能访问到它所在外部类的私有属性及方法:第二,外部类无法实现对同一 ...
- Java设计模式之-----工厂模式(简单工厂,抽象工厂)
一.工厂模式主要是为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的. 工厂模式在<Java与模式>中分为三类:1)简单工厂模式(Simple Factor ...
- 数据表格 - DataGrid - 字段排序
设置默认排序字段 sortName:"id",sortOrder:"desc",单独为每个字段设置排序 {field: "name", ti ...