【题目大意】

奶牛Bessie在0~N时间段产奶。农夫约翰有M个时间段可以挤奶,时间段[a,b]Bessie能挤到的牛奶量v。奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量。

【思路】

首先按各个时间段的开始时间进行排序。f[i]表示到第i个时间段位置挤奶量的最大值。

对于当前时间段,如果它之前的时间段的结束时间+休息时间≤当前时间段的开始时间(cow[j].e+r<=cow[i].s),那么进行比较(f[i]=max(f[i],f[j]+cow[i].v))。

【易错点】

注意f[i]的初值是cow[i].v,即只有当前时间段挤奶。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=+;
struct node
{
int s,e,v;
bool operator < (const node &x) const
{
return s<x.s;
}
}cow[MAXN];
int f[MAXN];
int n,m,r; int main()
{
scanf("%d%d%d",&n,&m,&r);
for (int i=;i<m;i++)
{
scanf("%d%d%d",&cow[i].s,&cow[i].e,&cow[i].v);
}
sort(cow,cow+m); for (int i=;i<m;i++) f[i]=cow[i].v;
for (int i=;i<m;i++)
for (int j=;j<i;j++)
{
if (cow[j].e+r<=cow[i].s)
f[i]=max(f[i],f[j]+cow[i].v);
} int ans=-;
for (int i=;i<m;i++) ans=max(ans,f[i]);
cout<<ans<<endl;
return ;
}

【动态规划】POJ3616-Milking Time的更多相关文章

  1. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

  2. poj3616 Milking Time(状态转移方程,类似LIS)

    https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...

  3. POJ3616 Milking Time —— DP

    题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  5. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  6. POJ3616 Milking Time 简单DP

    注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾 ...

  7. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  8. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

  9. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  10. 【POJ - 3616】Milking Time(动态规划)

    Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...

随机推荐

  1. Android控件——ToggleButton多状态按钮(实现灯泡的开关)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxoAAAFxCAIAAAB7jkm1AAAgAElEQVR4nOy9eXgUVb7/Dy7j3BnH8T

  2. 【codeforces85D】

    去实验培训回来了……写个题先玩玩 这题给人一种平衡树的感觉 但是呢,实际上操作离线+离散化+线段树一样能做 #include<bits/stdc++.h> #define lson (o& ...

  3. uoj#35 后缀排序(后缀数组模版)

    #include<bits/stdc++.h> #define N 100005 using namespace std; char s[N]; int a[N],c[N],t1[N],t ...

  4. Socket与URL通信比较

    转至链接:http://blog.csdn.net/qq_15848173/article/details/46328399 利用URL通信和Socket进行通信有很多相似之处.他们都是利用建立连接. ...

  5. .net设置浏览器的文本模式

    这段时间做个项目,做的时候因为之前习惯了Google的调试方式,所以就一直在google上面调试,今天项目成员大家的部分要整合,就放到ie8下面测试,但是遇到一个问题,就是用ie打开之后文本模式一直是 ...

  6. awk常见操作整理(更新)

    awk的基本结构 awk 'BEGIN{} pattern {} END {}' #pattern {} 部分是针对每行进行循环处理的,有pattern表示对匹配到的行处理,没有pattern表示对所 ...

  7. 关于Free的override不能省略的问题,切记,虚方法是可以被覆盖的方法。

     

  8. [PAT] 1143 Lowest Common Ancestor(30 分)1145 Hashing - Average Search Time(25 分)

    1145 Hashing - Average Search Time(25 分)The task of this problem is simple: insert a sequence of dis ...

  9. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...

  10. 比对两个Word文件内容是否一致的C#解决办法

    using System; using System.Windows.Forms; using System.Diagnostics; using Microsoft.Office.Interop.W ...