Description

You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very
popular, and receives many requests to use its two fine rooms, but unfortunately the previous director
was not very efficient, and it has been losing money for many years. The two rooms are of the same
size and arrangement. Therefore, each applicant wishing to hold a concert asks for a room without
specifying which. Each room can be used for only one concert per day.
In order to make more money, you have decided to abandon the previous fixed price policy, and rather
let applicants specify the price they are ready to pay. Each application shall specify a period [i, j] and
an asking price w, where i and j are respectively the first and last days of the period (1 ≤ i ≤ j ≤ 365),
and w is a positive integer in yen, indicating the amount the applicant is willing to pay to use a room
for the whole period.
You have received applications for the next year, and you should now choose the applications you
will accept. Each application should be either accepted for its whole period or completely rejected.
Each concert should use the same room during the whole applied period.
Considering the dire economic situation of the concert hall, artistic quality is to be ignored, and
you should just try to maximize the total income for the whole year by accepting the most profitable
applications.

Input
The input has multiple data sets, each starting with a line consisting of a single integer n, the number
of applications in the data set. Then, it is followed by n lines, each of which represents one application
with a period [i, j] and an asking price w yen in the following format.
i j w
A line containing a single zero indicates the end of the input.
The maximum number of applications in a data set is one thousand, and the maximum asking price
is one million yen.

Output

For each data set, print a single line containing an integer, the maximum total income in yen for the
data set.

Sample Input
4
1 2 10
2 3 10
3 3 10
1 3 10
6
1 20 1000
3 25 10000
5 15 5000
22 300 5500
10 295 9000
7 7 6000
8
32 251 2261
123 281 1339
211 235 5641
162 217 7273
22 139 7851
194 198 9190
119 274 878
122 173 8640
0

Sample Output
30
25500
38595

【题意】

  你有2个房间,有365天,有n个人找你租房,第i个人要从第xi到第yi天要一个房(任意一个),付wi的钱,求怎样安排收的钱最多

【分析】

  1~365天建一个点,st连1流量为2费用为0。

  根据输入的继续连边,比如第i个人要从第xi到第yi天要一个房(任意一个),付wi的钱那么建一条xi->yi+1流量为1,费用为wi的边。

  最后求最大费用最大流(去负跑最小费用最大流即可)。

代码如下:

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define Maxm 1001000
#define Maxn 400
#define INF 0xfffffff int n; struct node
{
int x,y,f,c,o,next;
}t[Maxm];int len; int first[Maxn],pre[Maxn],dis[Maxn],flow[Maxn];
bool inq[Maxn]; int mymin(int x,int y) {return x<y?x:y;}
int mymax(int x,int y) {return x>y?x:y;} void ins(int x,int y,int f,int c)
{
t[++len].x=x;t[len].y=y;t[len].f=f;t[len].c=c;
t[len].next=first[x];first[x]=len;t[len].o=len+;
t[++len].x=y;t[len].y=x;t[len].f=;t[len].c=-c;
t[len].next=first[y];first[y]=len;t[len].o=len-;
} queue<int > q;
bool bfs(int st,int ed)
{
while(!q.empty()) q.pop();
memset(dis,,sizeof(dis));
memset(inq,,sizeof(inq));
memset(pre,,sizeof(pre));
q.push(st);inq[st]=;dis[st]=;flow[st]=INF;
while(!q.empty())
{
int x=q.front();
for(int i=first[x];i;i=t[i].next) if(t[i].f>)
{
int y=t[i].y; if(dis[y]>dis[x]+t[i].c)
{
dis[y]=dis[x]+t[i].c;
pre[y]=i;
flow[y]=mymin(flow[x],t[i].f);
if(!inq[y]) {q.push(y);inq[y]=;}
}
}
q.pop();inq[x]=;
}
if(pre[ed]) return flow[ed];
return ;
} void max_flow(int x,int y)
{
int sum=,a;
while(a=bfs(x,y))
{
int now=y;
sum+=a*dis[y];
while(now!=x)
{
t[pre[now]].f-=a;
t[t[pre[now]].o].f+=a;
now=t[pre[now]].x;
}
}
printf("%d\n",-sum);
} int main()
{
while()
{
scanf("%d",&n);
if(n==) break;
memset(first,,sizeof(first));
len=;int mx=;
for(int i=;i<=n;i++)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
ins(x,y+,,-c);
mx=mymax(mx,y+);
}
int st=,ed=mx;
ins(st,,,);
for(int i=;i<mx;i++) ins(i,i+,,);
max_flow(st,ed);
}
return ;
}

[LA3796]

2016-05-25 13:27:56

【LA2796】Concert Hall Scheduling(最大费用最大流)的更多相关文章

  1. POJ2047 Concert Hall Scheduling(最小费用最大流)

    题目大概是有两个音乐厅,有n个乐队申请音乐厅,他们必须从第ii天到第ji天连续开音乐会且他们的开价是wi,每天每个音乐厅都只能供一个乐队进行音乐会.问接受哪些乐队的申请,获利最多能多少. 这题相当于在 ...

  2. UVaLive 2796 Concert Hall Scheduling (最小费用流)

    题意:个著名的音乐厅因为财务状况恶化快要破产,你临危受命,试图通过管理的手段来拯救它,方法之一就是优化演出安排,既聪明的决定接受或拒绝哪些乐团的演出申请,使得音乐厅的收益最大化.该音乐厅有两个完全相同 ...

  3. [板子]最小费用最大流(Dijkstra增广)

    最小费用最大流板子,没有压行.利用重标号让边权非负,用Dijkstra进行增广,在理论和实际上都比SPFA增广快得多.教程略去.转载请随意. #include <cstdio> #incl ...

  4. bzoj1927最小费用最大流

    其实本来打算做最小费用最大流的题目前先来点模板题的,,,结果看到这道题二话不说(之前打太多了)敲了一个dinic,快写完了发现不对 我当时就这表情→   =_=你TM逗我 刚要删突然感觉dinic的模 ...

  5. 【Codeforces717G】Underfail Hash + 最大费用最大流

    G. Underfail time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. ACM/ICPC 之 卡卡的矩阵旅行-最小费用最大流(可做模板)(POJ3422)

    将每个点拆分成原点A与伪点B,A->B有两条单向路(邻接表实现时需要建立一条反向的空边,并保证环路费用和为0),一条残留容量为1,费用为本身的负值(便于计算最短路),另一条残留容量+∞,费用为0 ...

  7. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  8. P3381 【模板】最小费用最大流

    P3381 [模板]最小费用最大流 题目描述 如题,给出一个网络图,以及其源点和汇点,每条边已知其最大流量和单位流量费用,求出其网络最大流和在最大流情况下的最小费用. 输入输出格式 输入格式: 第一行 ...

  9. 最小/大费用最大流模板(codevs1914)

    void addedge(int fr,int to,int cap,int cos){ sid[cnt].fr=fr;sid[cnt].des=to;sid[cnt].cap=cap;sid[cnt ...

随机推荐

  1. careercup-栈与队列 3.5

    3.5 实现一个MyQueue类,该类用两个栈来实现一个队列. 解答 队列是先进先出的数据结构(FIFO),栈是先进后出的数据结构(FILO), 用两个栈来实现队列的最简单方式是:进入队列则往第一个栈 ...

  2. 【转】cocos2d-x使用第三方的TTF字体库

    步骤一:找一个ttf字体库 步骤二:找到这个ttf字体库的真实名称 打开你的应用 "字体册"(MAC OS系统下),如下图操作): 找到了字体库真实名称,那么修改将其真名作为为此新 ...

  3. Java 授权内幕--转载

    在信息安全性领域,授权是世界的的中心,因为它是控制个体(即人.进程和计算机)对系统资源的访问权限的过程.直到最近,在 Java 安全体系结构中相关的问题都是“这段运行中的代码的访问权限是什么?” 随着 ...

  4. 汇编语言-[BX]和loop指令

    汇编语言-[BX]和loop指令 [BX]指令介绍 mov ax,[bx] 功能: bx为偏移地址,段地址默认为ds.因此,上面指令作用就是将ax中的数据送入内存ds:bx处,即:((ds)*16 + ...

  5. Windows Server 2008 R2 安装及配置指南

    一.安装需求: 1. 硬件需求条件 硬件 需求 处理器 最低:1.4 GHz(x64处理器) 注意:Windows Server 2008 for Itanium-Based Systems 版本需要 ...

  6. 码表 Unicode GBK UTF8 示例

    Unicode的编码形式与对应的字符串相互转换 /**  * Unicode的编码形式与对应的字符串相互转换  * @author 白乾涛  */ public class UnicodeUtils  ...

  7. c# 前端写代码的情况

    <%for(int i=0;i<list_model.Count;i++) { %> <div style=" padding-left:35px;padding-r ...

  8. 如何创建一个自己的【Composer/Packagist】包

    首先让我们踏着欢快的脚步去Github创建一个新库,这里取名 composer-car,又欢快的将它克隆到本地: $ git clone git@github.com:victorruan/compo ...

  9. HTML语言语法大全

    (文章转载至博客园 dodo-yufan) <! - - ... - -> 註解 <!> 跑馬燈 <marquee>...</marquee>普通捲動  ...

  10. 详解android:scaleType属性

    详解android:scaleType属性 转自:http://blog.csdn.net/encienqi/article/details/7913262    http://juliaailse. ...