POJ 3762 The Bonus Salary!(最小K覆盖)
来源:互联网 发布:python爬虫能做什么 编辑:程序博客网 时间:2024/06/05 00:42
POJ 3762 The Bonus Salary!
题目链接
题意:给定一些任务,每个任务有一个时间,有k天,一个时间只能执行一个任务,每个任务有一个价值,问怎么安排能得到最多价值
思路:典型的区间k覆盖问题
代码:
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <algorithm>#include <map>using namespace std;const int MAXNODE = 4505;const int MAXEDGE = 100005;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 = 2005;map<int, int> hash;int n, k, hn;int get(int x) {if (!hash.count(x)) hash[x] = hn++;return hash[x];}struct Task {int l, r, w;} task[N];int main() {while (~scanf("%d%d", &n, &k)) {hash.clear();hn = 1;int h1, m1, s1, h2, m2, s2, w;for (int i = 0; i < n; i++) {scanf("%d:%d:%d %d:%d:%d %d", &h1, &m1, &s1, &h2, &m2, &s2, &w);int t1 = h1 * 3600 + m1 * 60 + s1;int t2 = h2 * 3600 + m2 * 60 + s2;task[i].l = get(t1); task[i].r = get(t2); task[i].w = w;}gao.init(hn + 1);for (int i = 0; i < n; i++)gao.add_Edge(task[i].l, task[i].r, 1, -task[i].w);int pre = 0;for (map<int, int>::iterator it = hash.begin(); it != hash.end(); it++) {gao.add_Edge(pre, it->second, k, 0);pre = it->second;}gao.add_Edge(pre, hn, k, 0);printf("%d\n", -gao.Mincost(0, hn));}return 0;}
1 0
- POJ 3762 The Bonus Salary!(最小K覆盖)
- POJ 3762 The Bonus Salary!(区间k覆盖问题)
- POJ-3762-The Bonus Salary!
- POJ 3762 The Bonus Salary! 最小费用最大流
- The Bonus Salary! (poj 3762 离散化+最小费用流)
- poj3762 The Bonus Salary! (mcmf 区间K覆盖问题)
- POJ 3762 The Bonus Salary!(费用流)
- poj 3762 The Bonus Salary! 需离散化
- 【POJ】 3762 The Bonus Salary! 离散 + 费用流
- Destroying The Graph (poj 2125 最小点权覆盖)
- poj 2125 Destroying The Graph(最小割,最小点权覆盖)
- poj 3762(费用流+区间K覆盖)
- POJ 2125 Destroying The Graph (最小点权覆盖集)
- POJ 2125 Destroying The Graph 最小点权覆盖
- POJ 2125 Destroying The Graph 最小点权覆盖集
- 【POJ】2125 Destroying The Graph 最小点权覆盖
- poj 2125 Destroying The Graph 最小点权覆盖
- poj 2125 Destroying The Graph 最小点权覆盖集
- 为我签订去外地去的
- JNI常用函数
- R3修改线程上下文EIP实现的无模块注入
- querySelectorAll 方法相比 getElementsBy 系列方法有什么区别
- 【二分图|最大点独立集】POJ-1466 Girls and Boys
- POJ 3762 The Bonus Salary!(最小K覆盖)
- 如何Samba建立共享
- ASIHTTPRequest第三方网络请求详解
- java-反射
- RabbitMQ学习之spring整合发送同步消息
- java定时任务
- Oracle 删除表中记录 如何释放表及表空间大小
- 如何设计一个基于Node.js和Express的网站架构?
- 序列化-boost