码迷,mamicode.com
首页 > 其他好文 > 详细

poj 3161 Milking Time

时间:2018-02-01 23:16:25      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:post   color   const   nbsp   算法   string   double   abs   long   

题意:有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\n",maxe);
    }
    return 0;
}

 

poj 3161 Milking Time

标签:post   color   const   nbsp   算法   string   double   abs   long   

原文地址:https://www.cnblogs.com/lalalatianlalu/p/8401422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!