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

HDU 4502

时间:2015-03-16 09:46:26      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

直接贪心就好。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL __int64
using namespace std;

struct Job{
    int s,e,v;
    bool operator <(const Job &a)const{
        if(e<a.e) return true;
        return false;
    }
}job[1010];
int fee[1010];

int main(){
    int T,n,m;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&m,&n);
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&job[i].s,&job[i].e,&job[i].v);
        }
        sort(job,job+n);
        while(job[n-1].e>m)
        n--;
        if(n==0){
            puts("0");
            continue;
        }
        memset(fee,0,sizeof(fee));
        int tmp;
        for(int i=0;i<n;i++){
            fee[i]=job[i].v;
            tmp=0;
            for(int k=0;k<i;k++){
                if(job[k].e<job[i].s)
                tmp=max(tmp,fee[k]);
            }
            fee[i]+=tmp;
        }
        tmp=0;
        for(int i=0;i<n;i++)
        tmp=max(tmp,fee[i]);
        printf("%d\n",tmp);
    }
    return 0;
}

 

HDU 4502

标签:

原文地址:http://www.cnblogs.com/jie-dcai/p/4341055.html

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