zoukankan      html  css  js  c++  java
  • POJ3616(KB12-R dp)

    Milking Time

    Time Limit: 1000MS    Memory Limit: 65536K

    Total Submissions: 9459  Accepted: 3935

     

    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

     
    有将近一个月没做题,练一下手感。
     1 //2017-05-16
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int M = 1005;
    10 int dp[M];
    11 struct Milk
    12 {
    13     int bg, ed, eff;
    14     bool operator<(Milk x) const{
    15         return ed < x.ed;
    16     }
    17 }milk[M];
    18 
    19 int main()
    20 {
    21     int n, m, r;
    22     while(scanf("%d%d%d", &n, &m, &r)!=EOF)
    23     {
    24         memset(dp, 0, sizeof(dp));
    25         for(int i = 0; i < m; i++){
    26             scanf("%d%d%d", &milk[i].bg, &milk[i].ed, &milk[i].eff);
    27         }
    28         sort(milk, milk+m);
    29         int ans = 0;
    30         for(int i = 0; i < m; i++){
    31             if(milk[i].ed > n)break;
    32             dp[i] = milk[i].eff;
    33             for(int j = 0; j < i; j++){
    34                 if(milk[i].bg-r >= milk[j].ed){
    35                     dp[i] = max(dp[i], dp[j]+milk[i].eff);//dp[i]表示到第i个区间的最大值
    36                 }else break;
    37             }
    38             if(dp[i] > ans)ans = dp[i];
    39         }
    40         printf("%d
    ", ans);
    41     }
    42 
    43     return 0;
    44 }
  • 相关阅读:
    Java线程池,你了解多少?
    Git-常用命令
    CentOS6.6 编译Redis报错:"Newer version of jemalloc required"
    IDEA 常用快捷键
    Java并发编程(4)--生产者与消费者模式介绍
    CSS样式----浮动(图文详解)
    实现键盘记录的e.Whick和keyCode,兼容FireFox和IE
    如何用Fireworks制作经典的扫光字GIF动画
    asp.net中label控件设置字体大小
    [HttpException (0x80004005): 应用程序已预编译,因此不允许使用目录“/App_Code/”。]
  • 原文地址:https://www.cnblogs.com/Penn000/p/6863846.html
Copyright © 2011-2022 走看看