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

#include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct cow { int start; int endd; int price; }; bool cmp(cow a,cow b) { return a.start<b.start; } int main() { int n,m,r; cow a[1005]; cin>>n>>…
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 ha…
https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题的思路感觉有点陌生,又有点类似于求最长不降子序列的题. dp[i]为到第i个区间为止(该区间肯定有i)的最大挤奶量,最后从m个里面取最大. #include<iostream> #include<cstdio> #include<queue> #include<cst…
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 ha…
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10819   Accepted: 4556 Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she dec…
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. Fa…
http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个都有一个开始时间和结束时间和这个时间内的产奶量,任意一个时间段产奶之后,bessie都要休息r个时间,问如果安排产奶才能得到最大值. 注意这里m个时间其实都安排在n时间内,所以n其实是没用的. 设dp[i]是前i个时间内最多的产奶量    dp[i]=max(dp[i-1],dp[p[i]]+w[i…
注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾的工作时间,效率是e(保证前面有工作) 2:dp[i]=max(dp[i],e),表示前面没有工作 3:dp[i]=max(dp[i],dp[i-1]),保存到时间点i的最大价值 代码如下 #include<cstdio> #include<cstring> #include<a…
思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; ll n,m,r; struct node { ll start; ll end; ll p; }; node a[]; ll dp[]; bool cmp(const node & a,const node & b) { if(…
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个数中的一个. 思路 最显而易见的是使用二维数组动态规划计算. 比如dp[i][j]表示以第i行j列的位置作为终点的路线的最大权值. (注意区分初始化时的意义) 那么dp[i][j]的最大值取决于dp[i-1][j-1]和dp[i-1][j],从这两者之间筛选出最大值,加到dp[i][j]上,即为dp…