【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个公司.若干条可 ...
随机推荐
- 转:windows下命令行工具
转自: http://www.cnblogs.com/haochuang/p/5593411.html Windows下CMD不好用,远没有Linux,或者一些SSH工具用起来方便.其实Windows ...
- 小心 CSS3 Transform 引起的 z-index "失效"
https://www.douban.com/note/343402554/ http://www.jb51.net/css/255811.html 最后我直接removeClass;把transfo ...
- 在Java代码中使用iTextPDF生成PDF
1. 生成PDF 载入字体 static { FontFactory.register("/fonts/msyh.ttf"); FontFactory.register(" ...
- MakeCode 递归生成资源文件
static void yieldDir(DirectoryInfo dir, int depth, StringBuilder sb1, StringBuilder sb2) { var first ...
- 使用ViewBag传送数据从控制器至视图
前一篇<ASP.NET MVC读取XML并使用ViewData显示>http://www.cnblogs.com/insus/p/4308740.html 中,在控制器中使用了ViewDa ...
- QT 数据库编程四
//vmysql.cpp #include "vmysql.h" #include <QMessageBox> Vmysql::Vmysql() { mysql_ini ...
- ORACLE查出表所有的触发器及触发器详细信息
ORACLE查出表所有的触发器及触发器详细信息 一.查all_triggers表得到trigger_name Sql代码 select trigger_name from all_triggers w ...
- tomcat 新手上路
前提:本机先安装好JDK,保证常规java环境已经具备 1.下载Tomcat 7.0现在官网上好象已经没有安装程序版了,只有免解压zip版本(现在最新的版本是7.0.42) 下载地址 http://t ...
- c++基础 使用智能指针
三个智能指针模板(auto_ptr.unique_ptr和shard_ptr)都定义了类似指针的对象(c++11已将auto_ptr摒弃),可以将new获得(直接或间接) 的地址赋给这种对象.当智能指 ...
- MySQL for mac使用记录
一.登录 打开终端,输入/usr/local/mysql/bin/mysql -u root -p 初次进入mysql,密码为空.当出现mysql>提示符时,表示你已经进入mysql中.键入ex ...