bzoj 1642: [Usaco2007 Nov]Milking Time 挤奶时间(DP)
来源:互联网 发布:淘宝正版手办店 编辑:程序博客网 时间:2024/05/01 04:06
1642: [Usaco2007 Nov]Milking Time 挤奶时间
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 874 Solved: 505
[Submit][Status][Discuss]
Description
贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量。为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1。 Farmer John 计划好了 M (1 ≤ M ≤ 1,000) 个可以挤奶的时间段。每个时间段有一个开始时间(0 ≤ 开始时间 ≤ N), 和一个结束时间 (开始时间 < 结束时间 ≤ N), 和一个产量 (1 ≤ 产量 ≤ 1,000,000) 表示可以从贝茜挤奶的数量。Farmer John 从分别从开始时间挤奶,到结束时间为止。每次挤奶必须使用整个时间段。 但即使是贝茜也有她的产量限制。每次挤奶以后,她必须休息 R (1 ≤ R ≤ N) 个小时才能下次挤奶。给定Farmer John 计划的时间段,请你算出在 N 个小时内,最大的挤奶的量。
Input
第1行三个整数N,M,R.接下来M行,每行三个整数Si,Ei,Pi.
Output
最大产奶量.
Sample Input
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
Sample Output
43
所有时间段按尾排序之后DP,dp[i]表示前i小时的最大产量
因为n只有1000000所以可以不用离散化
这题有个技巧:题目中说每次产奶结束后牛要休息R小时,那么只要将所有任务开始时间往前延长R小时就行了
#include<stdio.h>#include<algorithm>using namespace std;typedef struct Miss{int val;int x, y;bool operator < (const Miss &b) const{if(y<b.y || y==b.y && x<b.x)return 1;return 0;}}Miss;Miss s[1005];int dp[1000005];int main(void){int n, i, m, r, p;scanf("%d%d%d", &n, &m, &r);n += 1;for(i=1;i<=m;i++){scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].val);s[i].x = max(s[i].x-r, 0)+1;}p = 1;sort(s+1, s+m+1);for(i=1;i<=n;i++){dp[i] = dp[i-1];while(s[p].y==i)dp[i] = max(dp[s[p].x-1]+s[p++].val, dp[i]);}printf("%d\n", dp[n]);}
阅读全文
1 0
- bzoj 1642: [Usaco2007 Nov]Milking Time 挤奶时间(DP)
- BZOJ 1642 [Usaco2007 Nov]Milking Time 挤奶时间 排序+DP
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- 【BZOJ 1642】 [Usaco2007 Nov]Milking Time 挤奶时间
- BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- 1642: [Usaco2007 Nov]Milking Time 挤奶时间
- bzoj1642 [Usaco2007 Nov]Milking Time 挤奶时间
- [BZOJ1642] [Usaco2007 Nov]Milking Time 挤奶时间
- bzoj1642[Usaco2007 Nov]Milking Time 挤奶时间
- Usaco2007 Nov 【Milking Time 】挤奶时间
- 洛谷P2889 [USACO07NOV]挤奶的时间Milking Time
- Milking Time(DP)
- bzoj 1620: [Usaco2008 Nov]Time Management 时间管理(贪心)
- bzoj 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏(floyd)
- bzoj 1733: [Usaco2005 feb]Secret Milking Machine 神秘的挤奶机 (二分+最大流)
- BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理
- bzoj 1620: [Usaco2008 Nov]Time Management 时间管理
- 将一个句子逆序
- python读取xml
- 数据结构与算法 (二) 线性表
- 电商实时交易风控系统
- 取得数组中最大的值
- bzoj 1642: [Usaco2007 Nov]Milking Time 挤奶时间(DP)
- 2018网易编程 独立的小易
- OI赛第二场t1Last mile of the way
- WOJ-5 Holding Animals
- hbase运行时ERROR:org.apache.hadoop.hbase.PleaseHoldException:Master is initializing的解决方法
- 深度学习笔记(七) RNN循环神经网络
- CSS —(弹性布局)
- ffmpeg 新老接口问题及对照集锦
- WOJ1157-Easy to Count