题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5855

Less Time, More profit

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

问题描述

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.

输入

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

输出

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

题意

有n个工厂,建每个工厂需要花费payi,并且要ti天才能建完。
有m个商店,每个商店能盈利proi,并且需要若干个指定的工厂给它提供原料(缺一不可)。
现在问如何在最短的时间内收益最大。

题解

最大权闭合子图的裸题。(百度文库里面的算法合集之最小割的论文里面有详细介绍最大权闭合子图)
我们二分时间t,然后问题转化成了对满足条件的工厂与商店之间的图求一个最大权闭合子图的问题。我们按照最大权闭合子图的建图方式连边就行了。
建图:
增设源点0,汇点n+m+1。
源点向每个能够满足条件的商店(如果商店的一个需求工厂在时间上不满足条件,那么这个商店就不满足条件,直接忽视它)连边,容量为商店的利润。
商店向需求工厂建边,容量为无穷大。
工厂向汇点建边,容量为工厂的花费。
然后跑最大流,判断在二分的时间下,是否能创造大于等于L的利润。

代码

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
//#define lson (o<<1)
//#define rson ((o<<1)|1)
//#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);//start----------------------------------------------------------------------const int maxn=444;struct Edge {int u,v,cap,flow;Edge(int u,int v,int c,int f):u(u),v(v),cap(c),flow(f) {}
};struct Dinic {int n,m,s,t;vector<Edge> egs;vector<int> G[maxn];bool vis[maxn];int d[maxn];int cur[maxn];void init(int n) {this->n=n;rep(i,0,n+1) G[i].clear();egs.clear();m=0;}void addEdge(int u,int v,int cap) {egs.pb(Edge(u,v,cap,0));egs.pb(Edge(v,u,0,0));m=egs.sz();G[u].pb(m-2);G[v].pb(m-1);}bool BFS() {clr(vis,0);queue<int> Q;Q.push(s);d[s]=0;vis[s]=1;while(!Q.empty()) {int x=Q.front();Q.pop();rep(i,0,G[x].sz()) {Edge& e=egs[G[x][i]];if(!vis[e.v]&&e.cap>e.flow) {vis[e.v]=1;d[e.v]=d[x]+1;Q.push(e.v);}}}return vis[t];}int DFS(int x,int a) {if(x==t||a==0) return a;int flow=0,f;for(int& i=cur[x]; i<G[x].size(); i++) {Edge& e=egs[G[x][i]];if(d[x]+1==d[e.v]&&(f=DFS(e.v,min(a,e.cap-e.flow)))>0) {e.flow+=f;egs[G[x][i]^1].flow-=f;flow+=f;a-=f;if(a==0) break;}}return flow;}int Maxflow(int s,int t) {this->s=s;this->t=t;int flow=0;while(BFS()) {clr(cur,0);flow+=DFS(s,INF);}return flow;}
} dinic;PII plants[maxn];
int pi[maxn],vis[maxn];
vector<int> G[maxn];int n,m,L;int isok(int mid) {dinic.init(n+m+2);clr(vis,0);for(int i=1; i<=m; i++) {rep(j,0,G[i].size()) {int v=G[i][j];if(plants[v].Y>mid) {vis[i]=1;break;}}}int sumv=0;for(int i=1; i<=m; i++) {if(vis[i]) continue;sumv+=pi[i];dinic.addEdge(0,i,pi[i]);rep(j,0,G[i].size()) {int v=G[i][j];dinic.addEdge(i,v+m,INF);}}rep(i,1,n+1) {if(plants[i].Y>mid) continue;dinic.addEdge(i+m,m+n+1,plants[i].X);}return sumv-dinic.Maxflow(0,n+m+1);
}void init() {rep(i,0,maxn) G[i].clear();
}int main() {int tc,kase=0;scanf("%d",&tc);while(tc--) {scanf("%d%d%d",&n,&m,&L);init();rep(i,1,n+1) {scanf("%d%d",&plants[i].X,&plants[i].Y);}rep(i,1,m+1) {scanf("%d",&pi[i]);int cnt;scanf("%d",&cnt);while(cnt--) {int x;scanf("%d",&x);G[i].push_back(x);}}printf("Case #%d: ",++kase);int l=0,r=1000000000;if(isok(r)<L) {puts("impossible");continue;}while(l+1<r) {int mid=l+(r-l)/2;if(isok(mid)>=L) r=mid;else l=mid;}printf("%d %d\n",r,isok(r));}return 0;
}//end-----------------------------------------------------------------------
/*
5 3 50
1 1
2 2
3 3
4 4
5 5
100 2 1 4
1 0
1 0
*/

转载于:https://www.cnblogs.com/fenice/p/5778116.html

HDU 5855 Less Time, More profit 最大权闭合子图相关推荐

  1. hdu 3917 Road constructions 最大权闭合子图

    样例说明: n(城市数目)   m(工程队数目) 每个工程队上交的税收 val[i] k(k个工程) xi   yi  ci  costi , 工程队ci承包由xi到yi,政府的补贴为costi 注意 ...

  2. 最大权闭合子图(poj 2987 Firing)

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10884   Accepted: 3286 Descript ...

  3. 2018.06.27Firing(最大权闭合子图)

    Firing Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 11558 Accepted: 3494 Description ...

  4. poj 2987 Firing (最大权闭合子图)

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10248   Accepted: 3110 Descript ...

  5. 最大权闭合子图(RMRC2017 Open-Pit Mining)

    闭合图:对于一个有向图G,存在点集合V,任取点u属于V,u的出边的另一个点也属于V,则为闭合图. 理解:任取一起点,终点必定是无出度的点. 最大权闭合子图:当每个点有一个权值w(有正有负),点权和最大 ...

  6. poj 2987 Firing【最大权闭合子图+玄学计数 || BFS】

    玄学计数 LYY Orz 第一次见这种神奇的计数方式,乍一看非常不靠谱但是仔细想想还卡不掉 就是把在建图的时候把正权变成w*10000-1,负权变成w*10000+1,跑最大权闭合子图.后面的1作用是 ...

  7. 最大权闭合子图(最小割)

    最大权闭合子图(最大流最小割) •参考资料 [1]最大权闭合子图 •权闭合子图 存在一个图的子图,使得子图中的所有点出度指向的点依旧在这个子图内,则此子图是闭合子图. 在这个图中有8个闭合子图:∅,{ ...

  8. 【转载】最大权闭合子图 【网络流】

    原文链接 定义 所谓闭合子图就是给定一个有向图,从中选择一些点组成一个点集V.对于V中任意一个点,其后续节点都仍然在V中. 建模 首先建立源点s和汇点t,将源点s与所有权值为正的点相连,容量为权值:将 ...

  9. Cogs 727. [网络流24题] 太空飞行计划(最大权闭合子图)

    [网络流24题] 太空飞行计划 ★★☆ 输入文件:shuttle.in 输出文件:shuttle.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] W 教授正在为国家航天中心计 ...

  10. #1398 : 网络流五·最大权闭合子图

    题目链接 结论 最大权闭合子图的权值 === 所有正权点之和−-−最小割 简单割(或最小割)将有向图分成两类,与源点sss相连的称为SSS,与汇点ttt相连的称为TTT 割的流量===与sss相连的正 ...

最新文章

  1. pyinstaller打包生成的exe文件(并设置运行时静默)
  2. 本人的博客只是工作期间随手记录的笔记而已,所以不会很详尽,由此给您带来的不便,恳请多多包涵~...
  3. 卷的作用_还在盲目的制作蛋糕卷吗?先来搞懂这几种蛋糕卷面糊~
  4. leetcode —— 39. 组合总和
  5. android方块模拟器,方块进化模拟器
  6. 匿名函数php作用,深入理解PHP中的匿名函数
  7. 看完不后悔系列,SQL语句执行慢怎么办,原因总结!!
  8. 查看npy文件中存的是什么
  9. LaTex,Mardown和TeXmacs:如何选择写作的正确姿势
  10. 二手苹果手机价格查询
  11. Go将中文转换为拼音
  12. Jenkins 身份验证及授权简介
  13. 关于VSCode安装 python 语法检测器插件 pylint 配置(Mac)
  14. edxposed显示未安装_Magisk与EdXposed框架安装实践(Android P及以上)
  15. jQuery 流星雨特效
  16. 4年功能测试月薪9.5K,3个月时间成功进阶自动化,跳槽涨薪6k后我的路还很长...
  17. a链接跳转到新的窗口
  18. java开发中常用的算法_总结一下项目开发过程中常用的到的一些加密算法。
  19. Java并发问题--乐观锁与悲观锁以及乐观锁的一种实现方式-CAS
  20. “希希敬敬对”团队作业——敏捷冲刺4

热门文章

  1. 中国计算机学会青年计算机科技论坛
  2. 5款在线制图工具分享,快来看看!
  3. 银行理财子与券商合作探讨(四):券商银行理财子数字化合作蓝图
  4. html在线人数统计代码,做一个简单的网站统计和在线人数统计
  5. P3554 [POI2013]LUK-Triumphal arch
  6. js 十六进制,八进制,二进制
  7. 在Storyboard中设置borderColor
  8. Qt实现柱状图、饼状图、折线图、曲线图
  9. 50个查询系列-第五个查询:查询没学过“叶平”老师课的同学的学号、姓名;...
  10. Unable to obtain current patch information due to error: 20001, ORA-20001: Latest xml inventory is n