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;
    }


  • 相关阅读:
    【新特性速递】数字输入框的前缀和后缀(位于输入框内部)
    【新特性速递】进度条,进度条,进度条
    【新特性速递】当法语遇上FineUI(Bonjour)!
    【新特性速递】自定义数字输入框的小数分隔符和千分位分隔符
    【经验分享】FineUICore中如何处理文件导出异常?
    【网友作品】服装分销系统架构与界面分享(基于FineUICore基础版)
    FineUIPro/Mvc/Core v6.3.0 正式发布了!
    星球居民突破 1700 人!
    【新特性速递】开关样式复选框增强!
    【新特性速递】为RenderField新增QuickSortField属性!
  • 原文地址:https://www.cnblogs.com/godweiyang/p/12203978.html
Copyright © 2011-2022 走看看