标签:uri 时间 climits determine str printf cep sam map
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: 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
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 }
标签:uri 时间 climits determine str printf cep sam map
原文地址:http://www.cnblogs.com/edward108/p/7649559.html