题目链接: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 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

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

Sample Output

43

Source

 
 
 
题解:
经典的类LIS题型(最长上升子序列)。
类似的题:HDU1160
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e3+; struct node
{
int st, en, val;
bool operator<(const node &x)const{
return st<x.st;
}
}a[MAXN];
int dp[MAXN];
int N, M, R; int main()
{
while(scanf("%d%d%d", &N, &M, &R)!=EOF)
{
for(int i = ; i<=M; i++)
scanf("%d%d%d", &a[i].st, &a[i].en, &a[i].val); sort(a+, a++M);
memset(dp, , sizeof(dp));
for(int i = ; i<=M; i++)
for(int j = ; j<i; j++)
if(j== || a[i].st>=a[j].en+R )
dp[i] = max(dp[i], dp[j] + a[i].val); int ans = -INF;
for(int i = ; i<=M; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
}
}

POJ3616 Milking Time —— DP的更多相关文章

  1. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  2. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  3. 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为结尾 ...

  4. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

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

    https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...

  6. POJ 3616 Milking Time DP题解

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

  7. POJ3616【基础DP】

    //因为同一点结束的时间段会有多个,这里没考虑: //无限wa: const int N=1e6+7; int b[N]; LL a[N]; LL dp[N]; struct asd{ int s; ...

  8. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  9. R - Milking Time DP

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

随机推荐

  1. 根据不同的产品id获得不同的下拉选项 (option传多值)

    <td> 没有 value 所以要在<td>里面加上input  同时text 为hidden这样就不会显示value的值 <td><select id='g ...

  2. 慕课网 微信小程序商城构建全栈应用 tp5【总结】

    1.异常处理: [代码越抽象,复用性越高] [封装性越好,适应代码变化的能力越强] [] <?php/** * Created by PhpStorm. * User: 14155 * Date ...

  3. HDU-2509-Be the Winner,博弈题~~水过~~

    Be the Winner Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ht ...

  4. [Go]程序实体

    Go语言中的程序实体包括变量.常量.函数.结构体.接口 1.常见声明变量的方式 package main import ( "flag" "fmt" ) fun ...

  5. 《Docker容器与容器云》读书笔记

    云计算平台 云计算是一种资源的服务模式,该模式可以实现随时随地.便捷按需地从可配置计算资源共享池中获取所需资源(如网络.服务器.存储.应用及服务),资源能够快速供应并释放,大大减少了资源管理工作开销. ...

  6. .NET下 JSON 的一些常用操作

    1.JSON的序列化和反序列化 Newtonsoft.Json dll 下载地址http://json.codeplex.com/ using System; using System.Collect ...

  7. POJ 1523 网络连通

    题目大意: 给你一个网络组,每台机子与其他机子的关系,让你找到所有的割点,如果没有割点,输出无 这道题目就是最直接的求割点问题,我在这里用的是邻接矩阵来存储机子之间的关系 割点问题的求解需要对深度优先 ...

  8. C++函数的重载,覆盖和隐藏(——高质量编程第14章)

      函数重载概念 只有C++才有重载的概念,C语言没有. 靠行参列表的不同来区别不同的重载函数, 若是全局函数和成员函数同名时,不算重载,因为它们的作用域不同,所以成员函数会将全局函数给隐藏(遮蔽)了 ...

  9. poj1523求割点以及割后连通分量数tarjan算法应用

    无向图,双向通道即可,tarjan算法简单应用.点u是割点,条件1:u是dfs树根,则u至少有2个孩子结点.||条件2:u不是根,dfn[u]=<low[v],v是u的孩子结点,而且每个这样的v ...

  10. uva 662

    dp +路径输出 #include <cstdio> #include <cstdlib> #include <cmath> #include <stack& ...