BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间【DP】

本文介绍了解决USACO 2007年11月赛题“挤奶时间”的一种动态规划方法。该方法通过构建以时间为下标的DP数组,实现了对奶牛挤奶顺序的有效优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

【题目描述】
传送门

【解题报告】

我们可以发现时间最大是 106 10 6 ,那么完全可以写一个以时间为下标的DP。

代码如下

#include<cstdio>
#include<algorithm>
using namespace std;
int Len,n,R,f[2000005],NowMax=0;
struct xcw{
    int L,R,w;
    bool operator <(const xcw b)const{return L<b.L;}
}a[1005];
int main(){
    #ifndef ONLINE_JUDGE
    freopen("prob.in","r",stdin);
    freopen("prob.out","w",stdout);
    #endif
    scanf("%d%d%d",&Len,&n,&R);
    for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i].L,&a[i].R,&a[i].w);
    sort(a+1,a+1+n);
    for(int i=0,j=1;i<=Len;i++){
        NowMax=max(NowMax,f[i]);
        for(;a[j].L==i&&j<=n;j++) f[a[j].R+R]=max(NowMax+a[j].w,f[a[j].R+R]);
    }
    for(int i=Len+1;i<=Len+R;i++) NowMax=max(NowMax,f[i]);
    printf("%d\n",NowMax);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值