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;
}

POJ 3762 The Bonus Salary!(最小K覆盖)的更多相关文章

  1. POJ 3762 The Bonus Salary!

    The Bonus Salary! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Origi ...

  2. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  3. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  4. POJ 3216 Repairing Company(最小路径覆盖)

    POJ 3216 Repairing Company id=3216">题目链接 题意:有m项任务,每项任务的起始时间,持续时间,和它所在的block已知,且往返每对相邻block之间 ...

  5. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

  6. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  7. poj 2594 Treasure Exploration(最小路径覆盖,可重点)

    题意:选出最小路径覆盖图中所有点,路径可以交叉,也就是允许路径有重复的点. 分析:这个题的难点在于如何解决有重复点的问题-方法就是使用Floyd求闭包,就是把间接相连的点直接连上边,然后就是求最小路径 ...

  8. POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)

    <题目链接> 题目大意: 机器人探索宝藏,有N个点,M条边.问你要几个机器人才能遍历所有的点. 解题分析: 刚开始还以为是最小路径覆盖的模板题,但是后面才知道,本题允许一个点经过多次,这与 ...

  9. poj 2594(可相交的最小路径覆盖)

    题目链接:http://poj.org/problem?id=2594 思路:本来求最小路径覆盖是不能相交的,那么对于那些本来就可达的点怎么处理,我们可以求一次传递闭包,相当于是加边,这样我们就可以来 ...

随机推荐

  1. android中利用HttpURLConnection进行Get、Post和Session读取页面。

    直接上代码,调用的时候要放在线程中. package slj.getsms; import java.io.BufferedReader; import java.io.InputStreamRead ...

  2. 一类划分关系和指数级生成函数,多项式exp的关系

    划分关系 姑且这么叫着 设满足性质 \(A\) 的集合为 \(S_A\),每个元素有标号 如果 \(S_B\) 是由若干个 \(S_A\) 组成的一个大集合 设 \(a_i\) 表示大小为 \(i\) ...

  3. html5 文档元素 header footer h1h2h4

    文档元素: 用于在页面的大布局, 区分各个主体和概念. 让整体清晰, 元素有语义, 进一步代替div 具体划分图示: (参考) <hgroup> <section> <n ...

  4. canvas中strokeRect的渲染问题>>strokeRect把一像素的边框渲染成两像素

    > 结论写在头 var oC = document.getElementById('c1'); var oGC = oC.getContext('2d'); oGC.strokeRect(50, ...

  5. Ajax实现表格实时编辑

    如果我们的对于一个表格中所有的数据都能在本页进行操作那该是多酷炫的一件事(用起来炒鸡爽)! 用Ajax就可以实现这个功能啦.废话不多说,下面贴出我写的demo吧哈哈.我用的TP框架(3.2)比较习惯啦 ...

  6. JDBC中处理事务,小Demo

    事务的四大特性(ACID):  原子性(Atomicity):事务中所有操作是不可再分割的原子单位.事务中所有操作要么全部执行成功,要么全部执行失败.  一致性(Consistency):事务执行 ...

  7. Google APAC----Africa 2010, Qualification Round(Problem A. Store Credit)----Perl 解法

    原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p0 问题描述: Problem You receive a cre ...

  8. 理解android中ListFragment和Loader

    一直以来不知Android中Loader怎么用,今天晚上特意花了时间来研究,算是基本上搞明白了,现在把相关的注释和代码发出来,以便笔记和给网友一个参考,错误之处还望大家给我留言,共同进步,这个例子采用 ...

  9. 瞥了一眼js

    JS打开超链接的几种形式1.window.open(''url'') 2.用自定义函数<script>function openWin(tag,obj){obj.target=" ...

  10. 关于CATransform3D矩阵变换的简单解析

    关于CATransform3D矩阵变换的简单解析 效果图: 我能能够用上的CATransform3D其实很简单,并不复杂. CATransform3D有着4种东西我们可以设置. 1. 透视效果(由m3 ...