• D


    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



    这题想法非常简单就是先排序,再判断第i个要不要加进时间表里(1,时间上是否符合.2,利益最大化)
    #include <iostream> //这题用到滚动数组,先对时间开始进行排序,dp[i]代表前i个时间段的效率
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    ll dp[1100];
    struct node
    {
        int start,ende,eff;
    }exa[1100];
    bool cmp(node x,node y)
    {
        if(x.start==y.start)
            return x.ende<y.ende;
        return x.start<y.start;
    }
    int main()
    {
        int n,m,r;
        cin>>n>>m>>r;
        memset(dp,0,sizeof(dp));
        for(int i=0;i<m;i++)
        {
            cin>>exa[i].start>>exa[i].ende>>exa[i].eff;
        }
        sort(exa,exa+m,cmp);
        for(int i=0;i<m;i++) dp[i]=exa[i].eff;
        ll ans=0;
        for(int i=0;i<m;i++)//判断第i个要不要加进去
        {
            for(int j=0;j<i;j++)
            {
                if(exa[j].ende+r<=exa[i].start) dp[i]=max(dp[i],dp[j]+exa[i].eff);
            }
            ans=max(ans,dp[i]);
        }
        cout<<ans<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    Java可重入锁ReentrantLock
    Java异步编程
    机器学习 pipeline
    Python 机器学习 唐宇迪泰坦尼克号【最新代码】
    引用sklearn报错ImportError: cannot import name 'cross_validation'
    python机器学习-模型优化(六)
    python机器学习-模型评估(五)
    python机器学习-建模(四)
    python机器学习-特征工程(三)
    Python机器学习-数据预处理(二)
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/10185868.html
Copyright © 2020-2023  润新知