poj 3762 The Bonus Salary! 需离散化
来源:互联网 发布:windows installer恢复 编辑:程序博客网 时间:2024/06/09 17:48
Description
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 than hh_Li : mm_Li : ss_Li.
Output
The output only contains a nonnegative integer --- the maximum total productivity score.
Sample Input
5 209:00:00 09:30:00 209:40:00 10:00:00 309:29:00 09:59:00 1009:30:00 23:59:59 407: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.
Source
有n个任务,每个任务都有一个区间,每完成一个任务就会得到一定的分数,每次只能做一个任务,而且要求做满此任务的整个时间段,给你k天的时间,问最多能够得到多少分。//2404K1266MS#include<iostream>#include<algorithm>#include<cstring>#include<queue>#include<cstdio>using namespace std;const int MAXN=100000;const int inf=10000000;int pre[MAXN]; // pre[v] = k:在增广路上,到达点v的边的编号为kint dis[MAXN]; // dis[u] = d:从起点s到点u的路径长为dint vis[MAXN]; // inq[u]:点u是否在队列中int path[MAXN];int head[MAXN];int NE,tot,ans,max_flow;int z[90000];int vist[MAXN];struct T{ int s,e,w;} time[2207];struct node{ int u,v,cap,cost,next;} Edge[MAXN];void addEdge(int u,int v,int cap,int cost){ Edge[NE].u=u; Edge[NE].v=v; Edge[NE].cap=cap; Edge[NE].cost=cost; Edge[NE].next=head[u]; head[u]=NE++; Edge[NE].v=u; Edge[NE].u=v; Edge[NE].cap=0; Edge[NE].cost=-cost; Edge[NE].next=head[v]; head[v]=NE++;}int SPFA(int s,int t) // 源点为0,汇点为sink。{ int i; for(i=s; i<=t; i++) dis[i]=inf; memset(vis,0,sizeof(vis)); memset(pre,-1,sizeof(pre)); dis[s] = 0; queue<int>q; q.push(s); vis[s] =1; while(!q.empty()) // 这里最好用队列,有广搜的意思,堆栈像深搜。 { int u =q.front(); q.pop(); for(i=head[u]; i!=-1; i=Edge[i].next) { int v=Edge[i].v; if(Edge[i].cap >0&& dis[v]>dis[u]+Edge[i].cost) { dis[v] = dis[u] + Edge[i].cost; pre[v] = u; path[v]=i; if(!vis[v]) { vis[v] =1; q.push(v); } } } vis[u] =0; } if(pre[t]==-1) return 0; return 1;}void end(int s,int t){ int u, sum = inf; for(u=t; u!=s; u=pre[u]) { sum = min(sum,Edge[path[u]].cap); } max_flow+=sum; //记录最大流 for(u = t; u != s; u=pre[u]) { Edge[path[u]].cap -= sum; Edge[path[u]^1].cap += sum; ans += sum*Edge[path[u]].cost; // cost记录的为单位流量费用,必须得乘以流量。 }}int main(){ int n,k,s,t; scanf("%d%d",&n,&k); memset(head,-1,sizeof(head)); memset(z,0,sizeof(z)); NE=ans=max_flow=s=0; int num=0,h,m,ss; for(int i=0; i<n; i++) { scanf("%d:%d:%d",&h,&m,&ss); time[i].s=h*3600+m*60+ss; z[num++]=time[i].s; scanf("%d:%d:%d",&h,&m,&ss); time[i].e=h*3600+m*60+ss; z[num++]=time[i].e; scanf("%d",&time[i].w); } sort(z,z+num); int e=1; memset(vist,0,sizeof(vist)); for(int i=0; i<num; i++) if(!vist[z[i]])vist[z[i]]=e++; for(int i=1; i<e-1; i++) addEdge(i,i+1,inf,0); for(int i=0; i<n; i++) addEdge(vist[time[i].s],vist[time[i].e],1,-time[i].w); addEdge(0,1,k,0); t=e-1; while(SPFA(s,t)) { end(s,t); } printf("%d\n",-ans); return 0;}
- poj 3762 The Bonus Salary! 需离散化
- 【POJ】 3762 The Bonus Salary! 离散 + 费用流
- POJ-3762-The Bonus Salary!
- The Bonus Salary! (poj 3762 离散化+最小费用流)
- POJ 3762 The Bonus Salary!(最小K覆盖)
- POJ 3762 The Bonus Salary! 最小费用最大流
- POJ 3762 The Bonus Salary!(费用流)
- POJ 3762 The Bonus Salary!(区间k覆盖问题)
- poj3762 The Bonus Salary! (mcmf 区间K覆盖问题)
- POJ(2761)Feed the dogs (树状数组+离散化+贪心)
- POJ 3666 Making the Grade (DP+离散化)
- poj 3666 Making the Grade dp 离散化
- [POJ 3666] Making the Grade (序列DP+离散化)
- poj 3666 Making the Grade ( dp 离散化 优化)
- POJ 3666 Making the Grade 【DP+离散化】
- POJ 3666 Making the Grade DP + 离散化 + 贪心
- 【POJ 3666】Making the Grade(离散化+DP)
- POJ 3666 Making the Grade 【DP + 离散化 + 贪心 】
- 最大权二分匹配
- LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
- 沉默中等待(愿与君共勉)
- PHP解释器引擎执行流程
- 一个操作系统的实现_十分钟完成的操作系统
- poj 3762 The Bonus Salary! 需离散化
- Timus 1025. Democracy in Danger 题解
- PAT1007 BASIC:素数对猜想 (20)
- asdasdasd来不来啊
- Keepalived工具安装
- Access restriction: The type BASE64Encoder is not accessible due to restrict
- sgu495
- 类 HttpURLConnection
- 恩恩,迁移完成。。。