Milking Time(DP)
个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和
d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此时的n是否可以一起挖,同时跳跃性的递归无法比较,
后面参考了网上的递推,他是确定这个n必须挖的最大值,则n前面的最大值+cost进行比较,仔细一想,这样是能求出挖这个
地方的最大值,所以后面输出就还要进行一轮最大值判断
for(int i=;i<m;i++){
d[i]=C[i].earn;
for(int j=;j<i;j++)
{
if(C[j].ends<=C[i].start)
d[i]=max(d[i],d[j]+C[i].earn); }
}
注意了,它上面的代表着是D此时的值,即挖i的最大值,因为满足无后续性,所以内循环可以从0到i,确定是否挖与不挖。多想想
Language:
Default Milking Time
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 Output * Line 1: The maximum number of gallons of milk that Bessie can product in the N hours Sample Input 12 4 2 Sample Output 43 #include<iostream> |
Milking Time(DP)的更多相关文章
- poj 3616 Milking Time(dp)
Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...
- 【POJ】3616 Milking Time(dp)
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10898 Accepted: 4591 Des ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
随机推荐
- oracle扩容
动态添加表空间: alter tablespace cbs_cos add datafile '/dba/oradata/ORADEVdatafile/cbs_cos02.dbf' size 100m ...
- Python编程-编码、文件处理、函数
一.字符编码补充知识点 1.文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就打开了启动了一个进程,是在内存中的,所以在编辑器编写的内容也都是存放与内存中的,断电后 ...
- P4317 花神的数论题
题目 洛谷 数学方法学不会%>_<% 做法 爆搜二进制下存在\(i\)位\(1\)的情况,然后快速幂乘起来 My complete code #include<bits/stdc++ ...
- mysql性能优化的一些建议
mysql性能优化的一些建议 1.EXPLAIN 你的 SELECT 查询 查看rows列可以让我们找到潜在的性能问题. 2.为关键字段添加索引,比如:where, order by, group b ...
- 0x5C 计数类DP
cf 559C 考虑到黑色的格子很少,那么我把(1,1)变成黑色,然后按每个黑色格子接近终点的程度排序,计算黑色格子不经过另一个黑色格子到达终点的方案,对于当前的格子,要减去在它右下角的所有方案数(注 ...
- CentOS 7 安装 docker-compose
compose是用来在docker中定义和运行复杂应用的小工具,比如在一个文件中定义多个容器,只用一行命令就可以让一切就绪并运行. 安装pip: 这里显示,找不到相应的包?? 说没有python-pi ...
- 找回J2EE 之再学习打卡记录
由于之前准备专心搞前端,就把一些java知识闲置了很久.导致...现在有点艰难. 所以!我决定,要找回他. 这是篇打卡记录.(每天一小时.监督自己!) Day1(2017-10-8.)
- HDU 5925 离散化
东北赛的一道二等奖题 当时学长想了一个dfs的解法并且通过了 那时自己也有一个bfs的解法没有拿出来 一直没有机会和时ji间xing来验证对错 昨天和队友谈离散化的时候想到了 于是用当时的思路做了一下 ...
- Linux嵌入式 -- 内核 - 内存管理
1. 逻辑地址 线性地址 物理地址 段式管理: 16位CPU,20根地址总线,可寻址1M内存,但是只有16位的寄存器,64K. 逻辑地址 = 段基地址 + 段内偏移地址 物理地址 PA = 段 ...
- list添加map问题
结论: list添加添加的是map的地址 List<Map<String, Object>> list = new ArrayList<>(); Map<St ...