POJ 3762 The Bonus Salary!
The Bonus Salary!
This problem will be judged on PKU. Original ID: 3762
64-bit integer IO format: %lld Java class name: Main
In order to encourage employees' productivity, ACM Company has made a new policy. At the beginning of a period, they give a list of tasks to each employee. In this list, each task is assigned a "productivity score". After the first K days, the employee who gets the highest score will be awarded bonus salary.
Due to the difficulty of tasks, for task i-th:
- It must be done from hh_Li : mm_Li : ss_Li to hh_Ri : mm_Ri : ss_Ri.
- This range of time is estimated very strictly so that anyone must use all of this time to finish the task.
Moreover, at a moment, each employee can only do at most one task. And as soon as he finishes a task, he can start doing another one immediately.
XYY is very hard-working. Unfortunately, he's never got the award. Thus, he asks you for some optimal strategy. That means, with a given list of tasks, which tasks he should do in the first K days to maximize the total productivity score. Notice that one task can be done at most once.
Input
The first line contains 2 integers N and K (1 ≤ N ≤ 2000, 0 ≤ K ≤ 100), indicating the number of tasks and days respectively. This is followed by N lines; each line has the following format:
hh_Li:mm_Li:ss_Li hh_Ri:mm_Ri:ss_Ri w
Which means, the i-th task must be done from hh_Li : mm_Li : ss_Li to hh_Ri : mm_Ri : ss_Ri and its productivity score is w. (0 ≤hh_Li, hh_Ri ≤ 23, 0 ≤mm_Li, mm_Ri, ss_Li, ss_Ri≤ 59, 1 ≤ w ≤ 10000). We use exactly 2 digits (possibly with a leading zero) to represent hh, mm and ss. It is guaranteed that the moment hh_Ri : mm_Ri : ss_Ri is strictly later thanhh_Li : mm_Li : ss_Li.
Output
The output only contains a nonnegative integer --- the maximum total productivity score.
Sample Input
5 2
09:00:00 09:30:00 2
09:40:00 10:00:00 3
09:29:00 09:59:00 10
09:30:00 23:59:59 4
07:00:00 09:31:00 3
Sample Output
16
Hint
The optimal strategy is:
Day1: Task1, Task 4
Day2: Task 3
The total productivity score is 2 + 4 + 10 = 16.
解题:最小费用最大流。离散化时间点。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int v,w,f,next;
arc(int x = ,int y = ,int z = ,int nxt = ){
v = x;
w = y;
f = z;
next = nxt;
}
};
arc e[];
int head[maxn],d[maxn],p[maxn],tot,S,T;
bool in[maxn];
int n,m,lisan[maxn<<],cnt,x[maxn],y[maxn],sc[maxn];
void add(int u,int v,int w,int f){
e[tot] = arc(v,w,f,head[u]);
head[u] = tot++;
e[tot] = arc(u,-w,,head[v]);
head[v] = tot++;
}
queue<int>q;
bool spfa(){
for(int i = S; i <= T; i++){
d[i] = INF;
p[i] = -;
in[i] = false;
}
while(!q.empty()) q.pop();
d[S] = ;
in[S] = true;
q.push(S);
while(!q.empty()){
int u = q.front();
q.pop();
in[u] = false;
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].f > && d[e[i].v] > d[u] + e[i].w){
d[e[i].v] = d[u] + e[i].w;
p[e[i].v] = i;
if(!in[e[i].v]){
in[e[i].v] = true;
q.push(e[i].v);
}
}
}
}
return p[T] > -;
}
int solve(){
int tmp = ,minV;
while(spfa()){
minV = INF;
for(int i = p[T]; ~i; i = p[e[i^].v])
minV = min(minV,e[i].f);
for(int i = p[T]; ~i; i = p[e[i^].v]){
tmp += minV*e[i].w;
e[i].f -= minV;
e[i^].f += minV;
}
}
return tmp;
}
int main(){
int hh,mm,ss;
while(~scanf("%d %d",&n,&m)){
tot = cnt = ;
memset(head,-,sizeof(head));
for(int i = ; i < n; i++){
scanf("%d:%d:%d",&hh,&mm,&ss);
x[i] = hh* + mm* + ss;
lisan[cnt++] = x[i];
scanf("%d:%d:%d",&hh,&mm,&ss);
y[i] = hh* + mm* + ss;
lisan[cnt++] = y[i];
scanf("%d",sc+i);
}
sort(lisan,lisan+cnt);
int cnt1 = ;
for(int i = ; i < cnt; i++)
if(lisan[i] != lisan[cnt1-]) lisan[cnt1++] = lisan[i];
cnt = cnt1;
S = ;
T = cnt;
for(int i = ; i < cnt; i++) add(i,i+,,m);
for(int i = ; i < n; i++){
int tx = lower_bound(lisan,lisan+cnt,x[i]) - lisan;
int ty = lower_bound(lisan,lisan+cnt,y[i]) - lisan;
add(tx,ty,-sc[i],);
}
printf("%d\n",-solve());
}
return ;
}
/*
5 2
09:00:00 09:30:00 2
09:40:00 10:00:00 3
09:29:00 09:59:00 10
09:30:00 23:59:59 4
07:00:00 09:31:00 3
*/
POJ 3762 The Bonus Salary!的更多相关文章
- POJ 3762 The Bonus Salary!(最小K覆盖)
POJ 3762 The Bonus Salary! 题目链接 题意:给定一些任务.每一个任务有一个时间,有k天.一个时间仅仅能运行一个任务,每一个任务有一个价值.问怎么安排能得到最多价值 思路:典型 ...
- ZOJ3762 The Bonus Salary!(最小费用最大流)
题意:给你N个的任务一定要在每天的[Li,Ri]时段完成,然后你只有K天的时间,每个任务有个val,然后求K天里能够获得的最大bonus. 思路:拿到手第一直觉是最小费用最大流,然后不会建图,就跑去想 ...
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- oracle视图索引
reate table fleet_header( day date,name varchar2(20), route_id number(5),fleet_id number(5)); crea ...
- Hibernate每个层次类一张表(使用注释)
在上一文章中,我们使用xml文件将继承层次映射到一个表. 在这里,我们将使用注释来执行同样的任务.需要使用@Inheritance(strategy = InheritanceType.SINGLE_ ...
随机推荐
- luogu3225 [HNOI2012]矿场搭建
题目大意 给出一个有$n(n\leq 500)$个节点的无向图,一个满足条件的点集$V$会使得对于图中的每一个节点$u$,满足路径起点为$u$终点$v\in V$的路径集合$P_u$中总存在至少两条路 ...
- Organize Your Train part II(hash)
http://poj.org/problem?id=3007 第一次用STL做的,TLE了,自己构造字符串哈希函数才可以.. TLE代码: #include <cstdio> #inclu ...
- 8.19noip模拟题
2017 8.19 NOIP模拟赛 by coolyangzc 共3道题目,时间3小时 题目名 高级打字机 不等数列 经营与开发 源文件 type.cpp/c/pas num.cpp/c/pas ...
- flume+flume+kafka消息传递+storm消费
通过flume收集其他机器上flume的监测数据,发送到本机的kafka进行消费. 环境:slave中安装flume,master中安装flume+kafka(这里用两台虚拟机,也可以用三台以上) m ...
- Python 1:环境搭建及运行第一个程序
在计算机控制面板中找到系统,然后点击高级系统设置,再点击环境变量,把安装的python.exe的目录复制到下面系统变量的path栏最后面,复制前加个分号以隔开前面的变量,然后按3次确定即可退出配置.具 ...
- POJ 3635 优先队列BFS
(感谢lyd学长的幻灯片) 注意vis数组的应用 在vis[i][j]中 i表示到了第i个点 j表示还剩j升油 vis[i][j]表示最小话费. 这样只需搜到话费比它少的更新入堆就OK了 //By: ...
- 反射找Controller中的方法
/// <summary> /// 根据接口编码APICode,调用相应的webapi方法,注意返回值是json字符串 /// </summary> /// <param ...
- SQLServer2008 关于CASE WHEN
CASE WHEN的两种格式 1.简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END 2.Case搜索函数 CASE ...
- 一周代码秀之[11.18~11.24 linq2xml面向对象]
1.xml <Sections> <Item key ="1" value ="孕哺期" canBeSelected="false& ...
- Vue初级
来学习vue.js的宝宝们应该都了解了什么是vue并且是有兴趣去学的,我也是自己学习vue,欢迎大家一起讨论. 现在,我么先自己尝试用vue来写个hello world吧. 一.创建一个 .html ...