zoukankan      html  css  js  c++  java
  • POJ3616

    题意

    在一个农场里,在长度为N时间(0<=x<=n-1)可以挤奶,但只能挤M次,且每挤一次就要休息t分钟,接下来给m组数据表示挤奶的时间与奶量求最大挤奶量(n<=1e6,m<=1e3,st<ed<=n)

    分析

    首先可以否定的是直接排序贪心取,因为val值随机,所以应该用dp

    定义:dp[i]:表示以第i头牛为结尾最大val和

    转移:类似最大上升子序列

    trick:需要排序!!!

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct node{
        int start,ends,efficiency;
        int li;
    }duan[1010];
    bool cmp(node xx,node yy)
    {
        if (xx.start!=yy.start)
        return xx.start<yy.start;
        return xx.ends<yy.ends;
    }
    int dp[1010];
    int main()
    {
        int n,m,r;
        scanf("%d%d%d",&n,&m,&r);
        n+=r;
        for (int i=0;i<m;i++)
        {
            scanf("%d%d%d",&duan[i].start,&duan[i].ends,&duan[i].efficiency);
            duan[i].ends+=r;
            //dp[i]=duan[i].efficiency;
        }
        sort(duan,duan+m,cmp);
        int s=0;
        for (int i=0;i<m;i++)
        {
            dp[i]=duan[i].efficiency;
            for (int j=0;j<i;j++)
            {
                if (duan[i].start>=duan[j].ends)
                dp[i]=max(dp[i],dp[j]+duan[i].efficiency);
            }
            s=max(s,dp[i]);
        }
        printf("%d
    ",s);
        return 0;
    }
    View Code
    要么优秀要么生锈
  • 相关阅读:
    Largest Rectangle in Histogram
    Valid Sudoku
    Set Matrix Zeroes
    Unique Paths
    Binary Tree Level Order Traversal II
    Binary Tree Level Order Traversal
    Path Sum II
    Path Sum
    Validate Binary Search Tree
    新手程序员 e
  • 原文地址:https://www.cnblogs.com/Superwalker/p/7978983.html
Copyright © 2011-2022 走看看