• poj 3161 Milking Time


    题意:有m段区间选取不相交的多个区间,是的加和最大

    思路:真是蠢的要死,变成区间就不会了,其实和lis一样(lis真是最好的算法 )

    代码:

    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <iostream>
    #include <algorithm>
    #define zero(a) fabs(a)<eps
    #define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
    #define min( x, y )  ( ((x) < (y)) ? (x) : (y) )
    #define lowbit(x) (x&(-x))
    typedef long long ll;
    const double pi=acos(-1.0);
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    const ll linf=0x3f3f3f3f3f3f3f3f;
    const int maxn = 1007;
    using namespace std;
    
    int n,m,k;
    struct node{int l,r,val;}a[maxn];
    int dp[maxn];
    bool cmp(node x,node y)
    {
        return x.l<y.l;
    }
    int main()
    {
        while(~scanf("%d%d%d",&n,&m,&k)){
            for(int i=0;i<m;i++){
                scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].val);
                a[i].r+=k;
            }
            sort(a,a+m,cmp);
            memset(dp,0,sizeof(dp));
            for(int i=0;i<m;i++){
                dp[i]=a[i].val;
                for(int j=0;j<i;j++){
                    if(a[i].l>=a[j].r){
                        dp[i]=max(dp[i],dp[j]+a[i].val);
                    }
                }
            }
            int maxe=0;
            for(int i=0;i<m;i++){
                maxe=max(maxe,dp[i]);
            }
            printf("%d
    ",maxe);
        }
        return 0;
    }
  • 相关阅读:
    开启sentry权限控制hue
    hive_server2的权限控制
    自带的simple认证
    tableau备份
    tableau分布式添加节点
    升级tableau版本
    tableau日常管理
    mavn Nexus Repository Manager漏洞
    第3章:打造命令行工具
    基于从库+binlog方式恢复数据
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/8401422.html
Copyright © 2020-2023  润新知