zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    MVC+EF 理解和实现仓储模式和工作单元模式 MVC+EF 理解和实现仓储
    ANDROID中BROADCASTRECEIVER的两种注册方式(静态和动态)详解
    企业微信通讯录组件一个机制
    linq查询DataTable中的某列去重数据
    C# 判断文件流类型
    js中使用settimeout的问题
    一个做流程的开源库
    javascript判断两个日期是否相等
    开发小贴士
    zepto.js与jquery.js
  • 原文地址:https://www.cnblogs.com/EchoZQN/p/10185868.html
Copyright © 2011-2022 走看看