POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10819 | Accepted: 4556 |
Description
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible.
Farmer John has a list of M (1 ≤ M ≤ 1,000) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour (0 ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency (1 ≤ efficiencyi ≤ 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must be milked through an entire interval.
Even Bessie has her limitations, though. After being milked during any interval, she must rest R (1 ≤ R ≤ N) hours before she can start milking again. Given Farmer Johns list of intervals, determine the maximum amount of milk that Bessie can produce in the N hours.
Input
* Line 1: Three space-separated integers: N, M, and R
* Lines 2..M+1: Line i+1 describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi
Output
* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours
Sample Input
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
Sample Output
43
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; struct node
{
int st, en, val;
bool operator<(const node &x)const{
return st<x.st;
}
}a[MAXN];
int dp[MAXN];
int N, M, R; int main()
{
while(scanf("%d%d%d", &N, &M, &R)!=EOF)
{
for(int i = ; i<=M; i++)
scanf("%d%d%d", &a[i].st, &a[i].en, &a[i].val); sort(a+, a++M);
memset(dp, , sizeof(dp));
for(int i = ; i<=M; i++)
for(int j = ; j<i; j++)
if(j== || a[i].st>=a[j].en+R )
dp[i] = max(dp[i], dp[j] + a[i].val); int ans = -INF;
for(int i = ; i<=M; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
}
}
最新文章
- Android笔记——SQLiteOpenHelper类
- 小记max-with与 max-device-width
- [控件] 加强版 TOneSelection (改良自 Berlin 10.1 TSelection)
- LDPC编译码基本原理
- (转载)JDOM/XPATH编程指南
- [DP] The 0-1 knapsack problem
- Linux系统下UDP发送和接收广播消息小样例
- SQL存储过程+游标 循环批量()操作数据
- fuelSources
- Activity中的startActivityResult,setResult,finish,onActivityResult的关系
- com.sun.jdi.InvocationException occurred invoking method.
- 找出N之内的所有完数
- 永久设置mysql中文乱码问题
- win7与centos虚拟机的共享文件夹创建
- Windows7 64位安装最新版本MySQL服务器
- 25 range打印100到0的连续整数
- js obj对象转formdata格式代码
- 使用C# HttpWebRequest进行多线程网页提交。Async httpclient/HttpWebRequest实现批量任务的发布及异步提交和超时取消
- re、词云
- 【EatBook】-NO.1.EatBook.1.JavaData.1.001-《JSON 必知必会-Introduction to JavaScript Object Notation》-
热门文章
- 洛谷P4779 Dijkstra 模板
- 记第一次开发安卓应用——IT之家RSS阅读器
- 理解js的几个关键问题(2): 对象、 prototype、this等
- 大数据学习——hadoop集群搭建2.X
- CDOJ 1220 The Battle of Guandu
- xtu read problem training 2 B - In 7-bit
- [luoguP1437] [HNOI2004]敲砖块(DP)
- [Vijos1512] SuperBrother打鼹鼠 (二维树状数组)
- loadrunner 并发操作集合点配置
- 【2018 Multi-University Training Contest 3】