Less Time, More profit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 468    Accepted Submission(s): 172

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)

最大权闭合图。源点与利润x建边,边权为利润值。花费y与汇建边,权值为花费值。  x与y之间的依赖关系 建边,权值为 无穷。期望总利润-最小割(最大流)就是能获得的最大利润。

本题因为有时间限制,所以加个二分。在满足利润>=L的情况下求最小时间。在最小时间下求最大利润。

  1. /* ***********************************************
  2. Author :guanjun
  3. Created Time :2016/8/17 13:55:10
  4. File Name :hdu5855.cpp
  5. ************************************************ */
  6. #include <iostream>
  7. #include <cstring>
  8. #include <cstdlib>
  9. #include <stdio.h>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <string>
  16. #include <math.h>
  17. #include <stdlib.h>
  18. #include <iomanip>
  19. #include <list>
  20. #include <deque>
  21. #include <stack>
  22. #define ull unsigned long long
  23. #define ll long long
  24. #define mod 90001
  25. #define INF 0x3f3f3f3f
  26. #define maxn 10010
  27. #define cle(a) memset(a,0,sizeof(a))
  28. const ull inf = 1LL << ;
  29. const double eps=1e-;
  30. using namespace std;
  31. struct Edge{
  32. int from,to,cap,flow;
  33. };
  34. struct node{
  35. int n,m,s,t;//节点数 边数 源点 汇点
  36. vector<Edge>edges;
  37. vector<int>G[maxn];
  38. bool vis[maxn];
  39. int d[maxn];
  40. int cur[maxn];
  41. void init(int n,int s,int t){
  42. this->n=n;
  43. this->s=s;
  44. this->t=t;
  45. for(int i=;i<n;i++)G[i].clear();
  46. edges.clear();
  47. m=;
  48. }
  49. void addEdge(int from,int to,int cap){
  50. edges.push_back({from,to,cap,});
  51. edges.push_back({to,from,,});
  52. m=edges.size();
  53. G[from].push_back(m-);
  54. G[to].push_back(m-);
  55. }
  56. bool BFS(){
  57. memset(vis,,sizeof vis);
  58. queue<int>que;
  59. que.push(s);
  60. d[s]=;
  61. vis[s]=true;
  62. while(!que.empty()){
  63. int x=que.front();que.pop();
  64. for(int i=;i<G[x].size();i++){
  65. Edge&e=edges[G[x][i]];
  66. if(!vis[e.to]&&e.cap>e.flow){
  67. vis[e.to]=true;
  68. d[e.to]=d[x]+;
  69. que.push(e.to);
  70. }
  71. }
  72. }
  73. return vis[t];
  74. }
  75. int DFS(int x,int a){
  76. if(x==t||a==)return a;
  77. int flow=,f;
  78. for(int& i=cur[x];i<G[x].size();i++){
  79. Edge& e=edges[G[x][i]];
  80. if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>){
  81. e.flow+=f;
  82. edges[G[x][i]^].flow-=f;
  83. flow+=f;
  84. a-=f;
  85. if(a==)break;
  86. }
  87. }
  88. return flow;
  89. }
  90. int Maxflow(int s,int t){
  91. this->s=s;
  92. this->t=t;
  93. int flow=;
  94. while(BFS()){
  95. memset(cur,,sizeof cur);
  96. flow+=DFS(s,INF);
  97. }
  98. return flow;
  99. }
  100. }ac;
  101. struct Node{
  102. int cost,time;
  103. }nod[];
  104.  
  105. int shop[][];
  106. int mon[];
  107. int TT,n,m,T,S,L;
  108.  
  109. int judge(int n,int m,int lim){
  110. T=n+m+;
  111. S=;
  112. int tot=;
  113. ac.init(m+n+,S,T);
  114. for(int i=;i<=m;i++){
  115. for(int j=;j<=shop[i][];j++)
  116. ac.addEdge(i,m+shop[i][j],INF);
  117. ac.addEdge(S,i,mon[i]);
  118. tot+=mon[i];
  119. }
  120. for(int i=;i<=n;i++){
  121. if(nod[i].time<=lim){
  122. ac.addEdge(i+m,T,nod[i].cost);
  123. }
  124. else ac.addEdge(i+m,T,INF);
  125. }
  126. tot-=ac.Maxflow(S,T);
  127. return tot;
  128. }
  129. int main()
  130. {
  131. #ifndef ONLINE_JUDGE
  132. freopen("in.txt","r",stdin);
  133. #endif
  134. //freopen("out.txt","w",stdout);
  135.  
  136. cin>>TT;
  137. for(int t=;t<=TT;t++){
  138. scanf("%d%d%d",&n,&m,&L);
  139. for(int i=;i<=n;i++){
  140. scanf("%d%d",&nod[i].cost,&nod[i].time);
  141. }
  142. for(int i=;i<=m;i++){
  143. scanf("%d %d",&mon[i],&shop[i][]);
  144. for(int j=;j<=shop[i][];j++){
  145. scanf("%d",&shop[i][j]);
  146. }
  147. }
  148. int l=,r=;
  149. int ans=;
  150. while(l<r){
  151. int mid=(r+l)/;
  152. ans=judge(n,m,mid);
  153. if(ans>=L){
  154. r=mid;
  155. }
  156. else l=mid+;
  157. }
  158. ans=judge(n,m,l);//注意这里
  159. printf("Case #%d: ",t);
  160. if(ans>=L)
  161. printf("%d %d\n",l,ans);
  162. else
  163. puts("impossible");
  164. }
  165. return ;
  166. }

HDU 5855Less Time, More profit的更多相关文章

  1. Yaoge’s maximum profit HDU - 5052

    Yaoge’s maximum profit Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  2. HDU 5855 Less Time, More profit 最大权闭合子图

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5855 Less Time, More profit Time Limit: 2000/1000 MS ...

  3. 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)

    Less Time, More profit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online

    意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...

  5. HDU 5855 Less Time, More profit

    二分t+最大权闭合图. 很显然二分那个t作为limit.每一个limit下,有一些边不能用了,然后要知道这种情况下怎么选点获得的价值最大. 这么想:一个shop想获得收益,就必须选择某一些plant, ...

  6. Hdu 5052 Yaoge’s maximum profit(树链剖分)

    题目大意: 给出一棵树.每一个点有商店.每一个商店都有一个价格,Yaoge每次从x走到y都能够在一个倒卖商品,从中得取利益.当然,买一顶要在卖之前.可是没次走过一条路,这条路上的全部商品都会添加一个v ...

  7. HDU 1712 分组背包

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. HDU5855 Less Time, More profit(最大权闭合子图)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...

  9. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

随机推荐

  1. x264介绍

    x264 编辑   H.264是ITU(International Telecommunication Unite 国际通信联盟)和MPEG(Motion Picture Experts Group ...

  2. 大项目之网上书城(六)——个人页面和书页面Demo

    目录 大项目之网上书城(六)--个人页面和书页面Demo 主要改动 1.user.jsp 代码 效果图 user.js 代码 3.shu.jsp 代码 效果图 4.其他小改动 LoginServlet ...

  3. js 技巧 (十)广告JS代码效果大全 【1】

    广告JS代码效果大全 1.[普通效果]     现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,介绍的这种效果,在1024*768分辨率下正常显示,在800*60 ...

  4. 75-ADMI,Average Directional Movement Index,平均方向性运动指标.(2015.7.1)

    ADMI,Average Directional Movement Index 平均方向性运动指标 Directional Movement Index,平均方向性运动指标.(2015.7.1)&qu ...

  5. jquery源码——noConflict实现

    实现方式很简单:在初始化的时候,记录当前全局中jQuery和$两个变量的的值,用_jQuery和_$分别存放,调用noConflict方法时,使用_jQuery和_$分别恢复对应的值,并且返回jQue ...

  6. 1004. 成绩排名 (20) (快速排序qsort函数的使用问题)

    读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...

  7. [luoguP3402] 最长公共子序列(DP + 离散化 + 树状数组)

    传送门 比 P1439 排列LCS问题,难那么一点点,只不过有的元素不是两个串都有,还有数据范围变大,树状数组得打离散化. 不过如果用栈+二分的话还是一样的. ——代码 #include <cs ...

  8. node框架express里面静态文件中间件express.static,根据路径名查找文件

    - 是express框架下的一个方法,可以根据请求路径名查找某个文件下文件名字和路径名相同的文件 - 3.X里面有20多个中间件,但是在4.X里面 只保留了express.static - 语法 ex ...

  9. 【HDOJ5713】K个联通块(状压DP,计数)

    题意:有一张无重边的无向图, 求有多少个边集,使得删掉边集里的边后,图里恰好有K个连通块. 1≤T≤201≤K≤N≤140≤M≤N∗(N+1)/21≤a,b≤N 思路:From http://blog ...

  10. React Native学习(十)—— 生命周期

    本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...