题意:奶牛Bessie在0~N时间段产奶。农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e。奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量。

详见代码

 #include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <iostream>
#define LL long long
using namespace std;
struct Node {
int s,e,v;
friend bool operator < (Node a,Node b) {
return a.s<b.s;
}
};
Node node[];
int main() {
int n,m,r;
while(~scanf("%d%d%d",&n,&m,&r)) {
for(int i=; i<m; i++) {
scanf("%d%d%d",&node[i].s,&node[i].e,&node[i].v);
node[i].e+=r;//每次增加休息时间
}
sort(node,node+m);//时间小的优先级高
int dp[];//i表示在i时间点前符合题意的最大值
memset(dp,,sizeof(dp));
for(int i=; i<m; i++) {
dp[i]=node[i].v;
for(int j=; j<i; j++) {
if(node[j].e<=node[i].s) {//判断条件
dp[i]=max(dp[i],dp[j]+node[i].v);
}
}
}
cout<<*max_element(dp,dp+m)<<endl;
}
return ;
}

POJ 3616 Milking Time 简单DP的更多相关文章

  1. POJ 3616 Milking Time (排序+dp)

    题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次 ...

  2. poj 3616 Milking Time (基础dp)

    题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...

  3. poj 3616 Milking Time(dp)

    Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...

  4. POJ 3616 Milking Time (字符串DP)

    题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. #include<iostream> #include< ...

  5. POJ 3616 Milking Time 【DP】

    题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量.思路:一定是 ...

  6. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  7. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  8. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  9. POJ 3616 Milking Time DP题解

    典型的给出区间任务和效益值,然后求最大效益值的任务取法. 属于一维DP了. 一维table记录的数据含义:到当前任务的截止时间前的最大效益值是多少. 注意. 这表示当前任务一定要选择,可是终于结果是不 ...

随机推荐

  1. leetcode345——Reverse Vowels of a String(C++)

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  2. Q105971:Converting a Regular GUID to a Compressed GUID

    Quote from:  http://flexerasoftware.force.com/articles/en_US/INFO/Q105971 Synopsis   The Windows Ins ...

  3. wamp5 忘记mysql root密码 重置方法

    wamp5比较恶心,忘记mysql root密码了,重新安装都没用,网上找了个文章可以修改root的密码. http://www.kuqin.com/database/20080306/4249.ht ...

  4. ajax GET和POST请求web api 的几种方式

    GET请求 1.无参数get请求 一般get请求有两种写法,一种是 $.get()   一种是$.ajax({type:"get"}), 我个人比较喜欢用后者. 下面例子主要是ge ...

  5. mysqli和mysql和pdo查询

      mysql mysql_connect($db_host, $db_user, $db_password); mysql_select_db($dn_name); $result = mysql_ ...

  6. 什么是php?以及mysqlnd与libmysqlclient

    今天想彻底搞清楚php与mysql的关系,于是在php官方网站(http://php.net/manual/en/mysqli.installation.php) 看了一下mysqli,mysql.感 ...

  7. IT新人养成与蘑菇理论

    (一)来源及定义    “蘑菇定律”最早是在上世纪70年代一批年轻的电脑程序员编写的.当时,美国一批电脑程序员意外发现,一批刚从学校毕业的新人参加了工作,这些人很难适应工作环境.在这种情况下,这些电脑 ...

  8. asp.net mvc 发送邮箱验证码

    public ActionResult Index() { /*第一种,利用Google的smtp来发送邮件*/ SmtpClient client = ); Random Rdm = new Ran ...

  9. Learn Docker

    Learn Docker A Container is to VM today, what VM was to Physical Servers a while ago. The workload s ...

  10. 5个有用的.net profiling工具(转)

    我们有时需要对研发的软件程序进行性能测试,这时需要用到一些Profilers工具.下面列出5个有用的.net Profilers: 1. JetBrains dotTrace JetBrains do ...