Milking Time

Time Limit: 1000MS Memory Limit: 65536K

Description

Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible.

Farmer John has a list of M (1 ≤ M ≤ 1,000) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour (0 ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency (1 ≤ efficiencyi ≤ 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must be milked through an entire interval.

Even Bessie has her limitations, though. After being milked during any interval, she must rest R (1 ≤ R ≤ N) hours before she can start milking again. Given Farmer Johns list of intervals, determine the maximum amount of milk that Bessie can produce in the N hours.

Input

  • Line 1: Three space-separated integers: N, M, and R
  • Lines 2..M+1: Line i+1 describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi

Output

  • Line 1: The maximum number of gallons of milk that Bessie can product in the N hours

Sample Input

12 4 2

1 2 8

10 12 19

3 6 24

7 10 31

Sample Output

43

题意:给予M时间区间且每个区间可以挤多少牛奶,每工作一个时间段需要休息R个小时,问在N个小时最多可以得到多少牛奶。

题解:一个上升序列问题的变形。

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath> using namespace std; const int maxn = 1050; struct node
{
int be,en,w;
}s[maxn];
int dp[maxn]; bool cmp(node a,node b)
{
if(a.be==b.be)
return a.en<b.en;
return a.be < b.be;
} int main()
{
int n,m,i,j,r,Max,mmax;
scanf("%d%d%d",&r,&m,&n);
for(i=0;i<m;i++)
scanf("%d%d%d",&s[i].be,&s[i].en,&s[i].w);
sort(s,s+m,cmp);
Max = 0;
for(i=0;i<m;i++)
{
mmax = 0;
for(j=0;j<i;j++)
{
if(s[j].en+n<=s[i].be&&mmax<dp[j])
mmax = dp[j];
};
dp[i] = mmax + s[i].w;
Max = max(Max,dp[i]);
}
printf("%d\n",Max);
return 0;
}

POJ-3616_Milking Time的更多相关文章

  1. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  2. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  3. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  4. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  5. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  6. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

  9. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  10. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

随机推荐

  1. mac 将本地文件上传到vps

    打开mac终端 假设通过ssh连接远程vps命令为. ssh root@194.10.10.23 -p92322 (说明:92322表示端口号,一般vps端口号默认是22) 那么复制本地文件到终端的命 ...

  2. Hibernate中的Query

    //1:创建query对象,方法里面写hql语句 Query query = session.createQuery("from User"); //2:利用query对象中的方法 ...

  3. wpf样式与行为

  4. 凸优化 & 1概念

    ---恢复内容开始--- 放射集合 系数之和为1 相加仍然能在集合内,就是 纺射集合 子空间加一个常熟 就是纺射集合 , 例题2.1 一类特殊的线性方程组的解可以看作纺射 集合 纺射包 aff C 是 ...

  5. Axure之添加点击页面

    添加悬停字体变色的效果 页面载入时的频道预设(我做错了,英文版本不知道那个是页面载入时的事件) 我的博客不够完善,看不到全部的图片.我后续会修改我的网站的

  6. SaaS launch Kit成回收宝和友盟云合作纽带,帮助提升3倍上云效率

    导语:叶飞表示,全球二手手机市场未来几年将发生巨大变革, 回收宝正进行积极布局.与阿里云开展紧密技术合作,回收宝期待成为这一变革的引领者. 7月26日,在阿里云上海峰会上,阿里云了发布SaaS生态战略 ...

  7. loadrunner录制脚本时登录密码转md5

    在录制用户注册登录脚本时,常常会遇到web程序对用户密码进行加密处理.在很多时候采用的加密方式为MD5. 这时有两种处理方式: 一.所有用户采用同一密码 例如:每个用户名的密码都为e10adc3949 ...

  8. Codeforces 449B

    题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. JS---案例:手风琴 (利用封装好的动画函数)

    案例:手风琴     封装好的动画函数在common.js里面     //function getStyle(element, attr) {...}     //function animate( ...

  10. awk notes

    字符串拼接 cat sql | awk '{print " ALTER TABLE  tableA   ALTER " $1 " TYPE " $2 " ...