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的情况下求最小时间。在最小时间下求最大利润。

/* ***********************************************
Author :guanjun
Created Time :2016/8/17 13:55:10
File Name :hdu5855.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
struct Edge{
int from,to,cap,flow;
};
struct node{
int n,m,s,t;//节点数 边数 源点 汇点
vector<Edge>edges;
vector<int>G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn];
void init(int n,int s,int t){
this->n=n;
this->s=s;
this->t=t;
for(int i=;i<n;i++)G[i].clear();
edges.clear();
m=;
}
void addEdge(int from,int to,int cap){
edges.push_back({from,to,cap,});
edges.push_back({to,from,,});
m=edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool BFS(){
memset(vis,,sizeof vis);
queue<int>que;
que.push(s);
d[s]=;
vis[s]=true;
while(!que.empty()){
int x=que.front();que.pop();
for(int i=;i<G[x].size();i++){
Edge&e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow){
vis[e.to]=true;
d[e.to]=d[x]+;
que.push(e.to);
}
}
}
return vis[t];
}
int DFS(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<G[x].size();i++){
Edge& e=edges[G[x][i]];
if(d[x]+==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>){
e.flow+=f;
edges[G[x][i]^].flow-=f;
flow+=f;
a-=f;
if(a==)break;
}
}
return flow;
}
int Maxflow(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(BFS()){
memset(cur,,sizeof cur);
flow+=DFS(s,INF);
}
return flow;
}
}ac;
struct Node{
int cost,time;
}nod[]; int shop[][];
int mon[];
int TT,n,m,T,S,L; int judge(int n,int m,int lim){
T=n+m+;
S=;
int tot=;
ac.init(m+n+,S,T);
for(int i=;i<=m;i++){
for(int j=;j<=shop[i][];j++)
ac.addEdge(i,m+shop[i][j],INF);
ac.addEdge(S,i,mon[i]);
tot+=mon[i];
}
for(int i=;i<=n;i++){
if(nod[i].time<=lim){
ac.addEdge(i+m,T,nod[i].cost);
}
else ac.addEdge(i+m,T,INF);
}
tot-=ac.Maxflow(S,T);
return tot;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout); cin>>TT;
for(int t=;t<=TT;t++){
scanf("%d%d%d",&n,&m,&L);
for(int i=;i<=n;i++){
scanf("%d%d",&nod[i].cost,&nod[i].time);
}
for(int i=;i<=m;i++){
scanf("%d %d",&mon[i],&shop[i][]);
for(int j=;j<=shop[i][];j++){
scanf("%d",&shop[i][j]);
}
}
int l=,r=;
int ans=;
while(l<r){
int mid=(r+l)/;
ans=judge(n,m,mid);
if(ans>=L){
r=mid;
}
else l=mid+;
}
ans=judge(n,m,l);//注意这里
printf("Case #%d: ",t);
if(ans>=L)
printf("%d %d\n",l,ans);
else
puts("impossible");
}
return ;
}

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. Java 序列化Serializable详解(附详细例子)

    Java 序列化Serializable详解(附详细例子) 1.什么是序列化和反序列化Serialization(序列化)是一种将对象以一连串的字节描述的过程:反序列化deserialization是 ...

  2. ffmpeg处理网络流

    最近遇到好几个人在问ffmpeg如何处理网络流,刚好前段时间也在做这方面,抽空整理了下,把主要代码发出来,希望对大家有用.为简单处理,我这里只简单介绍UDP接收TS流,其实只要是socket接收的都可 ...

  3. Python 中的变量还能这样理解(白话)

    一.案例分析 1.思考 计算软件测试大佬柠檬小姐姐,每月能存多少钱 # 计算软件测试大佬柠檬小姐姐,每月能存多少钱 # 坐标:深圳 # 2018年1月份 # 房租水电 4000元 # 伙食费 1000 ...

  4. 2017 计蒜之道 初赛 第一场 A 阿里的新游戏

    题链:https://nanti.jisuanke.com/t/15499 这题观察图纸可知成三线段上的相邻点之间的距离有1,2,3三种情况的,同时要成线段必然是同横坐标或者纵坐标,然后我们排除掉穿过 ...

  5. MySQL操作示例

    """ MySQL综合练习作业 """ # 1.自行创建测试数据: # 创建数据库 """ create da ...

  6. 如何在matlab里安装libsvm包

    有时我们需要用到SVR(支持向量回归)方法,而 matlab 自带的svm工具箱不能做回归分析,于是有了安装libsvm包的打算. 中间遇到一些困难,比如找不到编译器等等,经过一下午和一晚上的努力,在 ...

  7. 【04】AJAX接收服务器返回的数据

    AJAX接收服务器返回的数据 readyState 和 status 属性 readyState 属性保存有 XMLHttpRequest 对象的交互状态,从 0 到 4 变化: 0 :未初始化(还没 ...

  8. bzoj1052 [HAOI2007]覆盖问题 - 贪心

    Description 某人在山上种了N棵小树苗.冬天来了,温度急速下降,小树苗脆弱得不堪一击,于是树主人想用一些塑料薄膜把这些小树遮盖起来,经过一番长久的思考,他决定用3个L*L的正方形塑料薄膜将小 ...

  9. 听dalao讲课 7.26

    XFZ今天讲了些关于多项式求ln和多项式求导以及多项式求积分的东西 作为一个连导数和积分根本就不会的蒟蒻,就像在听天书,所以不得不补点前置知识 1.积分 积分是微积分学与数学分析里的一个核心概念.通常 ...

  10. 3.2 符号表之二叉查找树BST

    一.插入和查找 1.二叉查找树(Binary Search Tree)是一棵二叉树,并且每个结点都含有一个Comparable的键,保证每个结点的键都大于其左子树中任意结点的键而小于其右子树的任意结点 ...