UVA 1317 - Concert Hall Scheduling(网络流)
来源:互联网 发布:linux 命令输出不换行 编辑:程序博客网 时间:2024/06/16 17:42
UVA 1317 - Concert Hall Scheduling
题目链接
题意:现在有两个音乐厅,有一些人要租用,每次租一个区间的时间,给w钱,要求一个租的方案使得总收入最大,问总收入
思路:区间k覆盖问题,一个左闭右开区间可以建一条边,容量为1,代价为-w(因为要求最大),然后区间每个[i, i + 1]建一条边,容量2,代价0,然后跑一下费用流即可
代码:
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <algorithm>using namespace std;const int MAXNODE = 400;const int MAXEDGE = 5005 * 4;typedef int Type;const Type INF = 0x3f3f3f3f;struct Edge {int u, v;Type cap, flow, cost;Edge() {}Edge(int u, int v, Type cap, Type flow, Type cost) {this->u = u;this->v = v;this->cap = cap;this->flow = flow;this->cost = cost;}};struct MCFC {int n, m, s, t;Edge edges[MAXEDGE];int first[MAXNODE];int next[MAXEDGE];int inq[MAXNODE];Type d[MAXNODE];int p[MAXNODE];Type a[MAXNODE];void init(int n) {this->n = n;memset(first, -1, sizeof(first));m = 0;}void add_Edge(int u, int v, Type cap, Type cost) {edges[m] = Edge(u, v, cap, 0, cost);next[m] = first[u];first[u] = m++;edges[m] = Edge(v, u, 0, 0, -cost);next[m] = first[v];first[v] = m++;}bool bellmanford(int s, int t, Type &flow, Type &cost) {for (int i = 0; i < n; i++) d[i] = INF;memset(inq, false, sizeof(inq));d[s] = 0; inq[s] = true; p[s] = s; a[s] = INF;queue<int> Q;Q.push(s);while (!Q.empty()) {int u = Q.front(); Q.pop();inq[u] = false;for (int i = first[u]; i != -1; i = next[i]) {Edge& e = edges[i];if (e.cap > e.flow && d[e.v] > d[u] + e.cost) {d[e.v] = d[u] + e.cost;p[e.v] = i;a[e.v] = min(a[u], e.cap - e.flow);if (!inq[e.v]) {Q.push(e.v); inq[e.v] = true;}}}}if (d[t] == INF) return false;flow += a[t];cost += d[t] * a[t];int u = t;while (u != s) {edges[p[u]].flow += a[t];edges[p[u]^1].flow -= a[t];u = edges[p[u]].u;}return true;}Type Mincost(int s, int t) {Type flow = 0, cost = 0;while (bellmanford(s, t, flow, cost));return cost;}} gao;const int N = 1005;int n;int main() {while (~scanf("%d", &n) && n) {gao.init(367);for (int i = 0; i < 366; i++)gao.add_Edge(i, i + 1, 2, 0);int u, v, w;while (n--) {scanf("%d%d%d", &u, &v, &w);gao.add_Edge(u, v + 1, 1, -w);}printf("%d\n", -gao.Mincost(0, 366));}return 0;}
1 0
- UVA 1317 - Concert Hall Scheduling(网络流)
- uva 1317 - Concert Hall Scheduling(最小费用最大流)
- uva 1317 poj 2047 Concert Hall Scheduling(费用流)
- (beginer) 网络流(区间模型+最大费用流) UVA 1317 Concert Hall Scheduling
- LA 2796 Concert Hall Scheduling 费用流
- [POJ2047] Concert Hall Scheduling && 费用流
- POJ2047-Concert Hall Scheduling
- Concert Hall Scheduling UVALive
- poj 2047 Concert Hall Scheduling
- POJ-2047-Concert Hall Scheduling
- [TOJ 2663] Concert Hall Scheduling
- UVa 607 Scheduling Lectures(DP, 贪心)
- Uva 607 Scheduling Lectures (Dp+贪心)
- UVA 607-Scheduling Lectures(贪心+DP)
- UVa 690 - Pipeline Scheduling(回溯剪枝)
- uva 607 Scheduling Lectures
- UVA 607 Scheduling Lectures
- UVA - 607 Scheduling Lectures
- 软考进行时——面向过程设计VS面向对象设计
- 系统架构之设计模式一、基础知识
- 程序员想打基础看那几本书合适?
- 简介轻微癫痫有什么症状
- web弹层组件
- UVA 1317 - Concert Hall Scheduling(网络流)
- CODEVS 1100 自由落体
- 腾讯地图标记点击事件
- 一个通用的队列类,和C++STL中的Queue一样
- spring事务配置
- 【Spark亚太研究院系列丛书】Spark实战高手之路-第一章 构建Spark集群(第四步)(7)
- 上传第三方jar包到nexus
- 癫痫患者的饮食介绍
- 使用python函数库Pyside和Vispy实现交互式3D点云显示(一)