The Bonus Salary!

Time Limit: 2000ms
Memory Limit: 65536KB

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_Lihh_Ri ≤ 23, 0 ≤mm_Limm_Riss_Liss_Ri≤ 59, 1 ≤ w ≤ 10000). We use exactly 2 digits (possibly with a leading zero) to represent hhmm 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!的更多相关文章

  1. POJ 3762 The Bonus Salary!(最小K覆盖)

    POJ 3762 The Bonus Salary! 题目链接 题意:给定一些任务.每一个任务有一个时间,有k天.一个时间仅仅能运行一个任务,每一个任务有一个价值.问怎么安排能得到最多价值 思路:典型 ...

  2. ZOJ3762 The Bonus Salary!(最小费用最大流)

    题意:给你N个的任务一定要在每天的[Li,Ri]时段完成,然后你只有K天的时间,每个任务有个val,然后求K天里能够获得的最大bonus. 思路:拿到手第一直觉是最小费用最大流,然后不会建图,就跑去想 ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  7. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  8. oracle视图索引

    reate table fleet_header(  day date,name varchar2(20),  route_id number(5),fleet_id number(5)); crea ...

  9. Hibernate每个层次类一张表(使用注释)

    在上一文章中,我们使用xml文件将继承层次映射到一个表. 在这里,我们将使用注释来执行同样的任务.需要使用@Inheritance(strategy = InheritanceType.SINGLE_ ...

随机推荐

  1. 微信小程序初探(二、分页数据请求)

    大家好 波哥小猿又来啦[斜眼笑],昨天咱们讲了微信小程序简单数据请求,有没有照着教程实现请求的同学们啦 实现的同学举个爪[笑脸].哈哈,好了不扯犊子啦,我相信有的同学已经实现了简单的数据请求,没有实现 ...

  2. ListView实现简单列表

    ListView实现简单列表 效果图: 啥也没干的ListView张这样: fry.Activity01 package fry; import com.example.ListView.R; imp ...

  3. bzoj1179 [Apio2009]Atm——缩环最长路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1179 tarjan 缩环,然后求到有酒吧的点的最长路即可: 但一开始想缩环后用拓扑序求答案, ...

  4. yrzl-cloud

  5. POI合并单元边框问题解决方法

    http://blog.csdn.net/hardworking0323/article/details/51105430

  6. SpringMVC参数绑定(二)

    在springMVC中,提交请求的数据是通过方法形参来接收的,从客户端请求的key/value数据,经过参数绑定,将key/value数据绑定到controller形参上,然后再controller就 ...

  7. SAP computer之program counter

    Program counter The program is stored in memory with the first instruction at binary address 0000, t ...

  8. 用SQL Server验证用户名和密码

    用SQL Server验证用户名和密码,从页面输入的用户名和密码与数据库的用户名和密码进行匹配,正确则登入,错误则提醒. <form action="index.jsp" m ...

  9. Windows Live Writer 历史Blog修改的功能

    其实 WLW 有历史Blog修改的功能,我只是一直没有找到,就在打开“最近发布的日志”里面, 位于屏幕的右侧“打开”列表下. 最近发现记忆力越来越差了,BLOG看来是必须的了.

  10. emlog通过pjax实现无刷新加载网页--完美解决cnzz统计和javascript失效问题

    想要更详细了解pjax,需要查看官网 或者看本站文章:jQuery.pjax.js:使用AJAX和pushState无刷新加载网页(官网教程中文翻译) 效果看本站,音乐无刷新播放,代码高亮和复制js加 ...