poj3616 Milking Time

思路:

dp。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 using namespace std;
 5 typedef long long ll;
 6 ll n,m,r;
 7 struct node
 8 {
 9     ll start;
10     ll end;
11     ll p;
12 };
13 node a[1005];
14 ll dp[1005];
15 bool cmp(const node & a,const node & b)
16 {
17     if(a.start != b.start)
18     {
19         return a.start < b.start;
20     }
21     return a.end < b.end;
22 }
23 ll solve()
24 {
25     for(int i = 0;i < m;i ++)
26     {
27         dp[i] = a[i].p;
28         for(int j = 0;j < i;j ++)
29         {
30             if(a[j].end <= a[i].start)
31                 dp[i] = max(dp[i], dp[j] + a[i].p);
32         }
33     }
34     ll maxn = 0;
35     for(int i = 0;i < m;i ++)
36         maxn = max(maxn, dp[i]);
37     return maxn;
38 }
39 int main()
40 {
41     cin >> n >> m >> r;
42     for(int i = 0;i < m;i ++)
43     {
44         scanf("%lld%lld%lld",&a[i].start,&a[i].end,&a[i].p);
45         a[i].end += r;
46     }
47     sort(a, a + m,cmp);
48     cout << solve() << endl;
49     return 0;
50 } 
时间: 2024-09-28 21:19:40

poj3616 Milking Time的相关文章

POJ3616 Milking Time 【DP】

Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4917   Accepted: 2062 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 ≤

POJ3616——Milking Time

Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4964   Accepted: 2076 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 ≤

poj3616 Milking Time(状态转移方程,类似LIS)

https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题的思路感觉有点陌生,又有点类似于求最长不降子序列的题. dp[i]为到第i个区间为止(该区间肯定有i)的最大挤奶量,最后从m个里面取最大. 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #includ

POJ3616 Milking Time 简单DP

注意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

「kuangbin带你飞」专题十二 基础DP

layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 动态规划 传送门 A.HDU1024 Max Sum Plus Plus 题意 给你N个数,然后你分成M个不重叠部分,并且这M个不重叠部分的和最大. 思路 动态规划最大m字段和,dp数组,dp[i][j]表示以a[j]结尾的,i个字段的最大和 两种情况:1.第a[j

[BZOJ1642][Usaco2007 Nov]Milking Time 挤奶时间

1642: [Usaco2007 Nov]Milking Time 挤奶时间 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 878  Solved: 507 [Submit][Status][Discuss] Description 贝茜是一只非常努力工作的奶牛,她总是专注于提高自己的产量.为了产更多的奶,她预计好了接下来的N (1 ≤ N ≤ 1,000,000)个小时,标记为0..N-1. Farmer John 计划好了 M (1 ≤ M ≤

Milking Time

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

POJ3616(KB12-R dp)

Milking Time Time Limit: 1000MS    Memory Limit: 65536K Total Submissions: 9459  Accepted: 3935 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 ≤

[2016-03-28][POJ][3616][Milking Time]

时间:2016-03-28 17:27:03 星期一 题目编号:[2016-03-28][POJ][3616][Milking Time] #include <algorithm> #include <cstdio> using namespace std; const int maxm = 1000 + 10; struct Roo{ int l,r,v; bool operator < (const Roo & a)const{ return l < a.l