首页 > 其他 > 详细

poj 3161 Milking Time

时间:2018-02-01 22:34:57      阅读:225      评论:0      收藏:0      [点我收藏+]

题意:有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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!