个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和

d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此时的n是否可以一起挖,同时跳跃性的递归无法比较,

后面参考了网上的递推,他是确定这个n必须挖的最大值,则n前面的最大值+cost进行比较,仔细一想,这样是能求出挖这个

地方的最大值,所以后面输出就还要进行一轮最大值判断

  1. for(int i=;i<m;i++){
  2. d[i]=C[i].earn;
  3. for(int j=;j<i;j++)
  4. {
  5. if(C[j].ends<=C[i].start)
  6. d[i]=max(d[i],d[j]+C[i].earn);
  7.  
  8. }
  9. }

注意了,它上面的代表着是D此时的值,即挖i的最大值,因为满足无后续性,所以内循环可以从0到i,确定是否挖与不挖。多想想

Language:
Default
Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10442   Accepted: 4378

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: NM, 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

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

Sample Output

  1. 43
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<iomanip>
  6. #include<string>
  7. #include<algorithm>
  8. using namespace std;
  9. struct cow
  10. {
  11. int start,ends;
  12. int earn;
  13. }C[];
  14. int n,m,r;
  15. bool cmp(cow a,cow b){
  16. if(a.start==b.start)
  17. return a.ends<b.ends;
  18. return a.start<b.start;
  19. }
  20. int d[];
  21. int main(){
  22. cin>>n>>m>>r;
  23. for(int i=;i<m;i++){
  24. cin>>C[i].start>>C[i].ends>>C[i].earn;
  25. C[i].ends+=r;
  26. }
  27. sort(C,C+m,cmp);
  28. for(int i=;i<m;i++){
  29. d[i]=C[i].earn;
  30. for(int j=;j<i;j++)
  31. {
  32. if(C[j].ends<=C[i].start)
  33. d[i]=max(d[i],d[j]+C[i].earn);
  34.  
  35. }
  36. }
  37. int maxn=;
  38. for(int i=;i<m;i++)
  39. maxn=max(maxn,d[i]);
  40. cout<<maxn<<endl;
  41. return ;
  42. }
  1.  

Milking Time(DP)的更多相关文章

  1. poj 3616 Milking Time(dp)

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

  2. 【POJ】3616 Milking Time(dp)

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

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. 算法寒假实习面试经过之 滴滴(电话一面二面 offer)

    一面:1h 介绍比赛项目. lr与xgb的区别? xgb 为什么不用归一化,onehot? xgb 与 gbdt的区别. 做这些比赛你们的优势在哪,既然全是相同的套路. RCNN的原理, CNN的原理 ...

  2. C# 获取MD5值

    class CommonHelper { /// <summary> /// 通过字符串获取MD5值,返回32位字符串. /// </summary> /// <para ...

  3. Pandas基础用法-数据处理【全】-转

    完整资料:[数据挖掘入门介绍] (https://github.com/YouChouNoBB/data-mining-introduction) # coding=utf-8 # @author: ...

  4. spring boot 使用thymeleaf3.0以及thymeleaf的热部署

    spring boot 截止1.5.4,默认使用thymeleaf2.0,会有一些很蛋疼的地方比如xml格式之类的,具体哪些就不说了 -> 替换为3.0版本 pom中加入 <propert ...

  5. [kuangbin带你飞]专题十 匹配问题 一般图匹配

    过去做的都是二分图匹配 即 同一个集合里的点 互相不联通 但是如果延伸到一般图上去 求一个一般图的最大匹配 就要用带花树来解决 带花树模板 用来处理一个无向图上的最大匹配 看了一会还是不懂  抄了一遍 ...

  6. HDU 3966 & POJ 3237 & HYSBZ 2243 & HRBUST 2064 树链剖分

    树链剖分是一个很固定的套路 一般用来解决树上两点之间的路径更改与查询 思想是将一棵树分成不想交的几条链 并且由于dfs的顺序性 给每条链上的点或边标的号必定是连着的 那么每两个点之间的路径都可以拆成几 ...

  7. 可编辑的div模仿文本框缓存(使用AUTOCOMPLETE属性,off是不缓存,on是缓存(默认))

    用session实现的, 1.进当前页面就从session(a)中取( sessionStorage.getItem )(不管存在不存在,后续有合理的存储和删除); 2.离开当前页时删除这个sessi ...

  8. poj 2115 C Looooops 扩展欧几里德

    C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23616   Accepted: 6517 Descr ...

  9. 安装rackspace private cloud --2 overview

    Target hosts 包含以下 network bridges: LXC internal lxcbr0: 必须的,自动生成,containers的外网连接,不连接到host上任何物理/逻辑接口, ...

  10. JavaScript文件下载 兼容所有浏览器 不可跨域

    前端文件下载 兼容所有浏览器 download.js文件下载,几乎支持所有类型下载,详细内容参考官网 http://danml.com/download.html 引入文件 <script sr ...