zoukankan      html  css  js  c++  java
  • BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间

    1642: [Usaco2007 Nov]Milking Time 挤奶时间

    Description

    贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量。为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1。 Farmer John 计划好了 M (1 ≤ M ≤ 1,000) 个可以挤奶的时间段。每个时间段有一个开始时间(0 ≤ 开始时间 ≤ N), 和一个结束时间 (开始时间 < 结束时间 ≤ N), 和一个产量 (1 ≤ 产量 ≤ 1,000,000) 表示可以从贝茜挤奶的数量。Farmer John 从分别从开始时间挤奶,到结束时间为止。每次挤奶必须使用整个时间段。 但即使是贝茜也有她的产量限制。每次挤奶以后,她必须休息 R (1 ≤ R ≤ N) 个小时才能下次挤奶。给定Farmer John 计划的时间段,请你算出在 N 个小时内,最大的挤奶的量。

    Input

    1行三个整数NMR.接下来M行,每行三个整数SiEiPi

    Output

     最大产奶量.

    Sample Input

    12 4 2
    1 2 8
    10 12 19
    3 6 24
    7 10 31

    Sample Output

    43

    HINT

     

    注意:结束时间不挤奶

    ——华丽的分割线——

    这道题就是一个DP,状态表示是f[i]表示截至i时间,能获得的最大利润!不过关于题目的提示:结束时间不挤奶。我有点没看懂,加了这个特判就是错的,不加就AC了。。

    代码:

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    
    int n,m,r;
    struct FNode{
    	int start;
    	int end;
    	long long value;
    };
    FNode sec[1010];
    
    inline bool cmp(FNode a,FNode b){
    	if (a.start<b.start)return true;
    	if (a.end<b.end && a.start==b.start) return true;
    	return false;
    }
    
    long long f[1010];
    
    inline long long  remax(long long a,long long b){
    	if (a>b) return a;
    	return b; 
    }
    
    int main(){
    	scanf("%d%d%d",&n,&m,&r);
    	for (int i=1;i<=m;i++) scanf("%d%d%lld",&sec[i].start,&sec[i].end,&sec[i].value);
    	sort(sec+1,sec+m+1,cmp);
    	
    	memset(f,0,sizeof(f));
    	
    	for (int i=1;i<=m;i++){
    		f[i]=sec[i].value;
    		for (int j=1;j<i;j++){
    			if (sec[j].end+r<=sec[i].start){
    				f[i]=remax(f[i],f[j]+sec[i].value);
    			}
    		}
    	}
    	
    	long long Ans=0;
    	for (int i=1;i<=m;i++){
    		Ans=remax(Ans,f[i]);
    	}
    	
    	printf("%lld
    ",Ans);
    	return 0;
    } 



  • 相关阅读:
    php解析XML的两种方法
    Windows下xampp搭配php环境以及mysql的设置和php连接Mysql数据库
    管道
    Ubuntu文件系统
    Ubuntu如何使用Vscode写C++代码
    Ubuntu如何百度云盘下载
    Debug程序的使用
    寄存器
    汇编指令
    汇编第二章_寄存器
  • 原文地址:https://www.cnblogs.com/WNJXYK/p/4063952.html
Copyright © 2011-2022 走看看