zoukankan      html  css  js  c++  java
  • poj3616(Milking Time)

    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

    先对区间左端点从小到大排序,相同时右端点小的在前。然后从前往后依次处理,设dp[i]表示选第i个区间可以获得的最大值,那么对i之前任意与i相距大于等于r的区间j,dp[i]=max(dp[i],dp[j]+s[i].w)

    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <string>
    #include <map>
    #include <vector>
    #include <list>
    #include <set>
    #include <stack>
    #include <queue>
    #include <deque>
    #include <algorithm>
    #include <functional>
    #include <iomanip>
    #include <limits>
    #include <new>
    #include <utility>
    #include <iterator>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cctype>
    #include <cmath>
    #include <ctime>
    using namespace std;
    
    struct milk
    {
        int x, y, w;
        bool operator < (const milk& b) const
        {
            if (x == b.x)
                return y < b.y;
            return x < b.x;
        }
    };
    
    int main()
    {
        int n, m, r, dp[1005];
        milk s[1005];
        cin >> n >> m >> r;
        for (int i = 0; i < m; ++i)
            scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].w);
        sort(s, s+m);
        for (int i = 0; i < m; ++i)
            dp[i] = s[i].w;
        int ans = 0;
        for (int i = 0; i < m; ++i)
        {
            for (int j = 0; j < i; ++j)
                if (s[i].x >= s[j].y + r)
                    dp[i] = max(dp[i], dp[j]+s[i].w);
            ans = max(ans, dp[i]);
        }
        printf("%d
    ", ans);
        return 0;
    }


  • 相关阅读:
    递归获取指定盘符下的所有文件及文件夹
    单例模式和多线程有没有关系?
    eclipse启动tomcat时设置端口
    dozer转化对象
    枚举
    dubbo
    json
    配网失败问题
    esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
    base64编码
  • 原文地址:https://www.cnblogs.com/godweiyang/p/12203978.html
Copyright © 2011-2022 走看看