码迷,mamicode.com
首页 > 其他好文 > 详细

POJ_3616_Milking Time

时间:2017-10-11 13:06:06      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:uri   时间   climits   determine   str   printf   cep   sam   map   

Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10841   Accepted: 4564

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: NM, 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

 
  • 普通dp
  • 按时间排序,把休息的时间加在每个时间段的末尾

 

 

 1  #include <iostream>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <cmath>
 8 #include <vector>
 9 #include <queue>
10 #include <stack>
11 #include <set>
12 #include <map>
13 using namespace std;
14 typedef long long           LL ;
15 typedef unsigned long long ULL ;
16 const int    maxn = 1e3 + 10   ;
17 const int    inf  = 0x3f3f3f3f ;
18 const int    npos = -1         ;
19 const int    mod  = 1e9 + 7    ;
20 const int    mxx  = 100 + 5    ;
21 const double eps  = 1e-6       ;
22 const double PI   = acos(-1.0) ;
23 
24 struct node{
25     int u, v, w;
26     LL s;
27 };
28 bool cmp(const node &l, const node &r){
29     return l.u<r.u;
30 }
31 node dp[maxn];
32 int n, m, r, a, b, c;
33 LL ans;
34 int main(){
35     // freopen("in.txt","r",stdin);
36     // freopen("out.txt","w",stdout);
37     while(~scanf("%d %d %d",&n,&m,&r)){
38         ans=0;
39         for(int i=1;i<=m;i++){
40             scanf("%d %d %d",&dp[i].u,&dp[i].v,&dp[i].w);
41             dp[i].v+=r;
42             dp[i].s=dp[i].w;
43         }
44         sort(dp+1,dp+1+m,cmp);
45         for(int i=1;i<=m;i++){
46             for(int j=1;j<i;j++){
47                 if(dp[j].v<=dp[i].u){
48                     dp[i].s=max(dp[i].s,dp[j].s+dp[i].w);
49                 }
50             }
51             ans=max(ans,dp[i].s);
52         }
53         printf("%d\n",ans);
54     }
55     return 0;
56 }

 

 

 

POJ_3616_Milking Time

标签:uri   时间   climits   determine   str   printf   cep   sam   map   

原文地址:http://www.cnblogs.com/edward108/p/7649559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!