Concert Hall Scheduling UVALive
来源:互联网 发布:量化交易算人工智能吗 编辑:程序博客网 时间:2024/05/29 10:27
Concert Hall Scheduling UVALive - 2796
网络流·费用流
题目大意:
一个著名的音乐厅因为财务状况恶化快要破产,你临危受命,试图通过管理的手段来拯救它,方法之一就是优化演出安排,既聪明的决定接受或拒绝哪些乐团的演出申请,使得音乐厅的收益最大化。该音乐厅有两个完全相同的房间,因此个乐团在申请演出的时候并不会指定房间,你只需要随便分配一个即可。每个演出都会持续若干天,每个房间每天只能举行一场演出。申请数目n为不超过100的正整数,每个申请用3个整数i,j,w来表示,表示从第i天到第j天,愿意支付w元。
题解:
设置366个结点,表示365天(结点1到结点2表示第一天)。设置超级源点,连向第一个结点,容量为2(两个音乐厅),费用为0。设置超级汇点,使结点366连向它,容量为2,费用为0。然后,前365个结点,每个节点连向他的下一个节点,容量为2,费用为0,表示时间的流逝。最后对于每个申请,i到j + 1连一条边,容量为1,费用为负的w。跑费用流。
Code:
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#define D(x) cout<<#x<<" = "<<x<<" "#define E cout<<endlusing namespace std;const int N = 505;const int M = 10005;const int INF = 0x3f3f3f3f;int n,S,T;struct Edge{ int from,to,next,cap,flow,cost;}e[M*2];int head[N],ec=1;void clear(){ memset(head,0,sizeof(head)); ec=1; }void add(int a,int b,int cap,int cost){ ec++; e[ec].from=a; e[ec].to=b; e[ec].next=head[a]; head[a]=ec; e[ec].cap=cap; e[ec].flow=0; e[ec].cost=cost;}void add2(int a,int b,int cap,int cost){// D(a); D(b); D(cap); D(cost); E; add(a,b,cap,cost); add(b,a,0,-cost);}bool vis[N]; int d[N],pre[N];bool spfa(){ memset(vis,false,sizeof(vis)); memset(d,0x3f,sizeof(d)); queue<int> q; q.push(S); vis[S]=true; d[S]=0; while(!q.empty()){ int u=q.front(); q.pop(); vis[u]=false; for(int i=head[u];i;i=e[i].next){ int v=e[i].to; if(e[i].cap>e[i].flow && d[v]>d[u]+e[i].cost){ d[v]=d[u]+e[i].cost; pre[v]=i; if(!vis[v]){ vis[v]=true; q.push(v); } } } } return d[T]!=INF;}int mxf(){ int cost=0, flow=0, a; while(spfa()){ a=INF; for(int pos=T,i=pre[T]; pos!=S; pos=e[i].from,i=pre[pos]){ a=min(a,e[i].cap-e[i].flow); } for(int pos=T,i=pre[T]; pos!=S; pos=e[i].from,i=pre[pos]){ e[i].flow+=a; e[i^1].flow-=a; cost+=e[i].cost*a; } flow+=a; } return cost;}int main(){ freopen("a.in","r",stdin); while(~scanf("%d",&n) && n){ clear(); S=400; T=S+1; int a,b,c; for(int i=1;i<=n;i++){ scanf("%d%d%d",&a,&b,&c); add2(a,b+1,1,-c); } for(int i=1;i<=365;i++){ add2(i,i+1,2,0); } add2(S,1,2,0); add2(366,T,2,0); int cost=-mxf(); printf("%d\n",cost); }}
阅读全文
0 0
- Concert Hall Scheduling UVALive
- POJ2047-Concert Hall Scheduling
- poj 2047 Concert Hall Scheduling
- POJ-2047-Concert Hall Scheduling
- [TOJ 2663] Concert Hall Scheduling
- LA 2796 Concert Hall Scheduling 费用流
- [POJ2047] Concert Hall Scheduling && 费用流
- uva 1317 - Concert Hall Scheduling(最小费用最大流)
- UVA 1317 - Concert Hall Scheduling(网络流)
- uva 1317 poj 2047 Concert Hall Scheduling(费用流)
- (beginer) 网络流(区间模型+最大费用流) UVA 1317 Concert Hall Scheduling
- Concert Tour(Uvalive 6853)
- uvaLive 4475 - Dinner Hall(贪心)
- UVALive 6853Concert Tour(dp)
- UVALive 6853 - Concert Tour (dp)
- UVALive-3683 A Scheduling Problem(treedp)
- UVALive 3387 || HOJ 2196 Job Scheduling by Open Bidding
- UVALive 3683 A Scheduling Problem(树形DP)
- eclipse新建的web程序,其后创建了一个jsp文件,第一行就出现红叉
- 【Lucas】【数论】 17.6.2 组合数取模 题解
- bzoj 3944 Sum
- 2017计蒜之道初赛第四场AB两题题解
- Apparently wrong driver class specified for URL: class: com.mysql.jdbc.Driver
- Concert Hall Scheduling UVALive
- Android 最火的快速开发框架androidannotations配置详解
- 关键路径问题(括扑排序扩展)
- Lintcode——链表插入排序
- leetcode hard模式专杀之10Regular Expression Matching
- 【欧拉函数】【数论】17.6.2 数学题 题解
- 设计模式(11)-Composite 组合模式
- oracle procedure 心得
- PostgreSQL on Azure 初始使用