# [BZOJ1642][Usaco2007 Nov]Milking Time 挤奶时间

## 1642: [Usaco2007 Nov]Milking Time 挤奶时间

Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 878  Solved: 507 [Submit][Status][Discuss]

## Input

1行三个整数NMR.接下来M行，每行三个整数SiEiPi

最大产奶量．

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

43

## HINT

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
int n = 0;
char ch = *++ptr;
while(ch < '0' || ch > '9') ch = *++ptr;
while(ch <= '9' && ch >= '0'){
n = (n << 1) + (n << 3) + ch - '0';
ch = *++ptr;
}
return n;
}
const int maxn = 1000000 + 10, maxm = 1000 + 10;
struct Node{
int s, e, p;
Node(){}
Node(int _s, int _e, int _p): s(_s), e(_e), p(_p){}
bool operator < (const Node &x) const {
return e < x.e;
}
}a[maxm];
int dp[maxn] = {0};
int main(){
freopen("in.txt", "r", stdin);
fread(buf, sizeof(char), sizeof(buf), stdin);
int N, M, R;
for(int i = 1; i <= M; i++){
}
sort(a + 1, a + M + 1);
int time = 0, ans = 0;
for(int i = 1; i <= M; i++){
while(time <= a[i].s){
dp[time + 1] = max(dp[time], dp[time + 1]);
time++;
}
if(a[i].e + R >= N)
ans = max(ans, dp[a[i].s] + a[i].p);
else dp[a[i].e + R] = max(dp[a[i].e + R], dp[a[i].s] + a[i].p);
}
for(int i = 0; i < N; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
return 0;
};

posted @ 2017-09-13 21:42  Elder_Giang  阅读(115)  评论(0编辑  收藏  举报