博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU5855 Less Time, More profit(最大权闭合子图)
阅读量:4981 次
发布时间:2019-06-12

本文共 3395 字,大约阅读时间需要 11 分钟。

题目

Source

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

 

分析

题目大概说有n个工厂,建各个工厂分别要payi的花费和ti的时间,可以同时建工厂。此外还有m个商店,如果各个商店所需要k间工厂都建了,那么就得到proi的收益。现在希望收益大于等于l,问在建工厂所花时间最少的前提下,能获得的最大收益是多少。

 

二分时间,判定最大收益能否大于等于l;而求最大收益,这就是典型的最大权闭合子图的模型了,最小割求解即可。

 

代码

#include
#include
#include
#include
using namespace std;#define INF (1<<30)#define MAXN 444#define MAXM 444*888struct Edge{ int v,cap,flow,next;}edge[MAXM];int vs,vt,NE,NV;int head[MAXN];void addEdge(int u,int v,int cap){ edge[NE].v=v; edge[NE].cap=cap; edge[NE].flow=0; edge[NE].next=head[u]; head[u]=NE++; edge[NE].v=u; edge[NE].cap=0; edge[NE].flow=0; edge[NE].next=head[v]; head[v]=NE++;}int level[MAXN];int gap[MAXN];void bfs(){ memset(level,-1,sizeof(level)); memset(gap,0,sizeof(gap)); level[vt]=0; gap[level[vt]]++; queue
que; que.push(vt); while(!que.empty()){ int u=que.front(); que.pop(); for(int i=head[u]; i!=-1; i=edge[i].next){ int v=edge[i].v; if(level[v]!=-1) continue; level[v]=level[u]+1; gap[level[v]]++; que.push(v); } }}int pre[MAXN];int cur[MAXN];int ISAP(){ bfs(); memset(pre,-1,sizeof(pre)); memcpy(cur,head,sizeof(head)); int u=pre[vs]=vs,flow=0,aug=INF; gap[0]=NV; while(level[vs]
need[222];int isok(int t){ vs=0; vt=n+m+1; NV=vt+1; NE=0; memset(head,-1,sizeof(head)); int totpro=0; for(int i=1; i<=n; ++i){ if(time[i]<=t) addEdge(i+m,vt,pay[i]); } for(int i=1; i<=m; ++i){ bool flag=1; for(int j=0; j
t){ flag=0; break; } } if(flag==0) continue; addEdge(vs,i,pro[i]); totpro+=pro[i]; for(int j=0; j
=l) return res; return -1;}int main(){ int t; scanf("%d",&t); for(int cse=1; cse<=t; ++cse){ scanf("%d%d%d",&n,&m,&l); for(int i=1; i<=n; ++i){ scanf("%d%d",&pay[i],&time[i]); } for(int i=1; i<=m; ++i) need[i].clear(); for(int i=1; i<=m; ++i){ int a,b; scanf("%d%d",&pro[i],&a); for(int j=0; j
>1; if(isok(mid)!=-1) r=mid; else l=mid+1; } printf("Case #%d: ",cse); if(l==1000000001){ puts("impossible"); continue; } printf("%d %d\n",l,isok(l)); } return 0;}

 

转载于:https://www.cnblogs.com/WABoss/p/5777426.html

你可能感兴趣的文章
Struts2、Spring、Hibernate 高效开发的最佳实践(转载)
查看>>
使用cmd查看电脑连接过的wifi密码并将密码发送至指定邮箱(三)
查看>>
u3d 场景资源打包
查看>>
123
查看>>
hdu 1874
查看>>
最优比例生成树最优比率生成树 01分数规划问题
查看>>
ARM函数调用过程分析
查看>>
css样式重置方案 -解决浏览器差异
查看>>
distpicker使用记录
查看>>
[BZOJ3282]Tree(LCT)
查看>>
最终版详细设计
查看>>
GenePix Pro 3.0
查看>>
html移动端 -- meta-模板 + rem
查看>>
js-控制浏览器和移动端的后退按钮 . popstate
查看>>
[QT][SQLITE]学习记录二 日期查询
查看>>
hdu 4455 Substrings
查看>>
web传参
查看>>
Python 查找binlog文件
查看>>
Git——如何将本地项目提交至远程仓库
查看>>
Convert CString to std::string
查看>>