zoukankan      html  css  js  c++  java
  • POJ 3616 Milking Time

    Milking Time

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 6319   Accepted: 2660

    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_houriN), an ending hour (starting_houri < ending_houriN), 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 ≤ RN) 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

    这个题目意思是给定一些工作的开始时间,结束时间,和效率,当每次进行完一次工作以后需要休息,问在规定的时间内能进行的最大的效率的值。

    DP轻松解决,排序一下开始时间,然后用一个一维的dp数组表示在第i个工作为最后一个工作的最大效率值

    在符合上一个工作的结束时间加上休息时间在当前的工作的开始时间的前提下,有转移方程:

    dp[i] = max(dp[i], dp[j] + data[i].ef)   其中j是i前面的工作

    代码如下:

    /*************************************************************************
    	> File Name: Milking_Time.cpp
    	> Author: Zhanghaoran
    	> Mail: chilumanxi@xiyoulinux.org
    	> Created Time: Wed 28 Oct 2015 10:00:38 PM CST
     ************************************************************************/
    
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    
    using namespace std;
    
    struct node{
        unsigned long long st, et, ef;
    }data[1010];
    
    int N, M, R;
    unsigned long long dp[1010];
    
    int max(unsigned long long a, unsigned long long b){
        return a > b ? a : b;
    }
    bool cmp(node a, node b){
        if(a.st < b.st)
            return true;
        else
            return false;
    }
    
    int main(void){
        scanf("%d%d%d", &N, &M, &R);
        int Max = 0;
        for(int i = 1; i <= M; i ++){
            scanf("%llu%llu%llu", &data[i].st, &data[i].et, &data[i].ef);
        }
        sort(data + 1, data + M + 1, cmp);
        for(int i = 1; i <= M; i ++){
            dp[i] = data[i].ef;
        }
        for(int i = 2; i <= M; i ++){
            for(int j = 1; j < i; j ++){
                if(data[j].et + R <= data[i].st){
                    dp[i] = max(dp[i], dp[j] + data[i].ef);
                }
            }
            if(Max < dp[i])
                Max = dp[i];
        }
    
        printf("%d
    ", Max);
    
    }


  • 相关阅读:
    时统设备简介和标准汇总
    html页面元素铺满屏幕
    JavaScript之单线程
    JavaScript 内存模型
    数据-内存-变量
    python+selenium2自动化---通过js脚本给时间控件赋值
    Linux常用命令---文件创建、查找
    python+selenium2自动化---使用pytesseract和Pillow实现验证码识别
    python+selenium2自动化---屏幕截图
    Linux常用命令---find
  • 原文地址:https://www.cnblogs.com/chilumanxi/p/5136064.html
Copyright © 2011-2022 走看看