Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)

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

作者头像
饶文津
修改于 2023-09-21 11:16:51
修改于 2023-09-21 11:16:51
72100
代码可运行
举报
文章被收录于专栏:饶文津的专栏饶文津的专栏
运行总次数:0
代码可运行

Less Time, More profit

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

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.InputFirst 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 payiti(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)

Source

2016 Multi-University Training Contest 9

 M个商店,N个工厂,每个商店获利的条件是建设了指定的k个工厂。求总获利不小于L,工厂建设的时间最大值最小是多少。

 工厂到汇点建一条边pay[i],源点到商店建一条边pro[i],商店到需要的工厂建一条边INF,商店的总收益-最小割就是答案。

可以看看国家集训队论文:Amber《最小割模型在信息学竞赛中的应用》

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#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, -1, sizeof d);
    queue<int>q;
    q.push(st);
    d[st] = 0;
    while(!q.empty())
    {
        int i,k=q.front();
        q.pop();
        for(i = 1; i <= ed; i++)
            if(arc[k][i] > 0 && d[i] == -1)
            {
                d[i] = d[k] + 1;
                q.push(i);
            }
    }
    return d[ed]>0;
}
int dinic (int k, int low)
{
    if(k == ed)return low;
    int a,i;
    for(i = 1; i <= ed; i++)
        if(d[i] == d[k] + 1&&  arc[k][i] > 0 &&(a = dinic(i, min(low, arc[k][i]))))
        {
            arc[k][i] -= a;
            arc[i][k] += a;
            return a;
        }
    return 0;
}
int cmp(plant a,plant b){
    return a.t<b.t;
}
int main() {
    sf(t);
    for(int cas=1;cas<=t;cas++){
        printf("Case #%d: ",cas);
        scanf("%d%d%d",&n,&m,&l);
        for(int i=1;i<=n;i++){
            scanf("%d%d",&pt[i].pay,&pt[i].t);
            pt[i].id=i;
        }
        for(int i=1;i<=m;i++){
            sf(s[i].pro);
            sf(s[i].k);
            s[i].t=0;
            for(int j=1;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+1,pt+1+n,cmp);
        int ok=0;
        st=n+m+1,ed=st+1;
        for(int i=1;i<=n;i++){
            memset(arc,0,sizeof arc);
            for(int j=1;j<=i;j++)
                arc[pt[j].id][ed]=pt[j].pay;
            tot=0;
            for(int j=1;j<=m;j++)if(s[j].t<=pt[i].t){
                tot+=s[j].pro;
                arc[st][j+n]=s[j].pro;
                for(int k=1;k<=s[j].k;k++)
                arc[j+n][s[j].pt[k]]=INF;
            }
            ans = 0;
            while(bfs())
                while(tans=dinic(st, INF)) ans += tans;
            ans=tot-ans;
            if(ans>=l){
                printf("%d %d\n",pt[i].t,ans);
                ok=1;
                break;
            }
        }
        if(!ok)puts("impossible");
    }
}

工厂按时间排序再依次增大最大时间,这样是140ms,改成二分以为会更快,结果960ms,去了注释们再交一次居然超时了。可能是dinic用的是邻接矩阵的原因。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-08-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
图论-网络流-最大流--POJ1273Drainage Ditches(Dinic)
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch. Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
风骨散人Chiam
2020/10/28
4510
图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)
Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “impossible” mission ----- to make it slow for the army of City Colugu to reach the airport. City Colugu has n bus stations and m roads. Each road connects two bus stations directly, and all roads are one way streets. In order to keep the air clean, the government bans all military vehicles. So the army must take buses to go to the airport. There may be more than one road between two bus stations. If a bus station is destroyed, all roads connecting that station will become no use. What’s Gabiluso needs to do is destroying some bus stations to make the army can’t get to the airport in k minutes. It takes exactly one minute for a bus to pass any road. All bus stations are numbered from 1 to n. The No.1 bus station is in the barrack and the No. n station is in the airport. The army always set out from the No. 1 station. No.1 station and No. n station can’t be destroyed because of the heavy guard. Of course there is no road from No.1 station to No. n station. Please help Gabiluso to calculate the minimum number of bus stations he must destroy to complete his mission.
风骨散人Chiam
2020/10/28
3620
BUPT2017 wintertraining(15) #1 题解
求逆元。以前写过题解,http://www.cnblogs.com/flipped/p/5193777.html
饶文津
2020/06/02
2950
BUPT2017 wintertraining(15) #1 题解
【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
Tom is a commander, his task is destroying his enemy’s transportation system. Let’s represent his enemy’s transportation system as a simple directed graph G with n nodes and m edges. Each node is a city and each directed edge is a directed road. Each edge from node u to node v is associated with two values D and B, D is the cost to destroy/remove such edge, B is the cost to build an undirected edge between u and v. His enemy can deliver supplies from city u to city v if and only if there is a directed path from u to v. At first they can deliver supplies from any city to any other cities. So the graph is a strongly-connected graph. He will choose a non-empty proper subset of cities, let’s denote this set as S. Let’s denote the complement set of S as T. He will command his soldiers to destroy all the edges (u, v) that u belongs to set S and v belongs to set T.  To destroy an edge, he must pay the related cost D. The total cost he will pay is X. You can use this formula to calculate X:
饶文津
2020/06/02
2890
【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
hdu------(3549)Flow Problem(最大流(水体))
Flow Problem Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 8203    Accepted Submission(s): 3817 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, you
Gxjun
2018/03/26
6470
【POJ 1273】Drainage Ditches(网络流)
一直不明白为什么我的耗时几百毫秒,明明差不多的程序啊,我改来改去还是几百毫秒。 ...一个小时后:明白了,原来把最大值0x3f(77)取0x3f3f3f3f就把时间缩短为16ms了。可是为什么原来那样没有WA呢?哦,明白了,因为最大值写小了,dicnic会多跑几遍。 嗯顺便:0x3f3f3f3f也就是1061109567,也就是10^9级别的,是一个很大的数,而且加上一个10^9级别以下的数字也不会溢出。所以很多时候最大值取这个会比较好。最大的int是0x7fffffff,可以用常量INT_MAX 代替。
饶文津
2020/06/02
4160
hdu----149850 years, 50 colors(最小覆盖点)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1695    Accepted Submission(s): 931 Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating
Gxjun
2018/03/22
5680
hdu----149850 years, 50 colors(最小覆盖点)
图论--网络流--最大流 HDU 2883 kebab(离散化)
Problem Description Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled
风骨散人Chiam
2020/10/28
2890
hdu 4009 Transfer water(最小型树图)
Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3995    Accepted Submission(s): 1438 Problem Description XiaoA lives in a village. Last year flood rained the village. So they decide
Gxjun
2018/03/26
6270
hdu  4009  Transfer water(最小型树图)
HDU 3388 Coprime(容斥原理+二分)
Coprime Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 849    Accepted Submission(s): 232 Problem Description Please write a program to calculate the k-th positive integer that is coprime with m
ShenduCC
2018/04/26
6120
HDU-3237-Help Bubu
ACM模版 描述 题解 代码 #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using
f_zyj
2018/01/09
6270
HDU-3237-Help Bubu
HDU 1695 GCD (欧拉函数,容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9046    Accepted Submission(s): 3351 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y)
ShenduCC
2018/04/26
5040
【HDU 6036】Division Game (NTT+数学)
题意 屏幕快照 2020-06-02 下午3.40.23.png 题解 屏幕快照 2020-06-02 下午3.40.36.png 代码 #include <bits/stdc++.h> #define rep(i,l,r) for(int i=l,ed=r;i<ed;++i) #define mem(a,b) memset(a,b,sizeof(a)) typedef long long ll; using namespace std; const ll P = (235 << 22) + 1; cons
饶文津
2020/06/02
3890
【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or
饶文津
2020/05/31
3640
BZOJ 2127: happiness(最小割解决集合划分)
Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友。这学期要分文理科了,每个同学对于选择文科与理科有着自己的喜悦值,而一对好朋友如果能同时选文科或者理科,那么他们又将收获一些喜悦值。作为计算机竞赛教练的scp大老板,想知道如何分配可以使得全班的喜悦值总和最大。 Input 第一行两个正整数n,m。接下来是六个矩阵第一个矩阵为n行m列 此矩阵的第i行第j列的数字表示座位在第i行第j列的同学选择文科获得的喜悦值。第二个矩阵为n行m列 此矩
attack
2018/04/12
7430
BZOJ 2127: happiness(最小割解决集合划分)
【 HDU 4936 】Rainbow Island (hash + 高斯消元)
BUPT2017 wintertraining(15) #5B HDU - 4936 2014 Multi-University Training Contest 7 F
饶文津
2020/06/02
3830
【 HDU 4936 】Rainbow Island (hash + 高斯消元)
YbtOJ 582「网络流」大收藏家
共有 n 名收藏家参加了这次大会,每个人都带了一种与众不同的藏品来,其中第 i 个收藏家带了 a_i 个自己类型的藏品。
yzxoi
2022/09/19
3290
图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days. Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
风骨散人Chiam
2020/10/28
4130
HDU 4135 Co-prime(容斥原理)
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3313    Accepted Submission(s): 1286 Problem Description Given a number N, you are asked to count the number of integers between A and B i
ShenduCC
2018/04/26
6430
POJ 2987 Firing
Description You’ve finally got mad at “the world’s most stupid” employees of yours and decided to do
attack
2018/04/12
6010
相关推荐
图论-网络流-最大流--POJ1273Drainage Ditches(Dinic)
更多 >
加入讨论
的问答专区 >
1产品KOL擅长5个领域
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
    本文部分代码块支持一键运行,欢迎体验
    本文部分代码块支持一键运行,欢迎体验