POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616
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: N, M, 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
#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的更多相关文章
- POJ3616 Milking Time【dp】
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- poj-3616 Milking Time (区间dp)
http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...
- 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为结尾 ...
- 动态规划 POJ3616 Milking Time
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...
- poj3616 Milking Time(状态转移方程,类似LIS)
https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...
- POJ 3616 Milking Time DP题解
典型的给出区间任务和效益值,然后求最大效益值的任务取法. 属于一维DP了. 一维table记录的数据含义:到当前任务的截止时间前的最大效益值是多少. 注意. 这表示当前任务一定要选择,可是终于结果是不 ...
- POJ3616【基础DP】
//因为同一点结束的时间段会有多个,这里没考虑: //无限wa: const int N=1e6+7; int b[N]; LL a[N]; LL dp[N]; struct asd{ int s; ...
- poj3616 Milking Time
思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- R - Milking Time DP
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
随机推荐
- 利用scrapy获取抽屉新热榜的标题和内容以及新闻地址保存到本地
1.安装scrapy pip3 install scrapy 2.打开terminal,cd 到想要创建程序的目录下 3.创建一个scrapy项目 在终端输入:scrapy startproject ...
- python 数据库操作产生中文乱码的解决办法
1.执行python mysql数据库查询操作时,产生中文乱码 #!/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb db = MySQLd ...
- selenium 3+python3.6+firefox的windows详细环境搭建以及小demo
最近也是学习了下selenium和python,就记录了下在自己工作机上环境的搭建过程以及小demo 1,安装python3.6.1 我是去官网直接下载当前最新版的python3.6.1 官网网址为h ...
- Leetcode 310.最小高度树
最小高度树 对于一个具有树特征的无向图,我们可选择任何一个节点作为根.图因此可以成为树,在所有可能的树中,具有最小高度的树被称为最小高度树.给出这样的一个图,写出一个函数找到所有的最小高度树并返回他们 ...
- MyBatis使用Mapper动态代理开发Dao层
开发规范 Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象,代理对象的方法体同原始Dao接口实现类方法. Mappe ...
- codevs 1743 反转卡片 rope or splay
[codevs1743]反转卡片 题目描述 Description [dzy493941464|yywyzdzr原创] 小A将N张卡片整齐地排成一排,其中每张卡片上写了1~N的一个整数,每张卡片上的数 ...
- [转]Android SDK下载和更新失败的解决方法
今天更新sdk,遇到了更新下载失败问题: Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xmlFetched ...
- 我的Github,个人博客
Github: github.com/wuxinwei 个人博客: blog.wuxinwei.org
- FusionCharts for Flex 如何更改图表数据
FusionCharts allows to change chart data and re-render the chart, after it has loaded on the user’s ...
- HDU——2444 The Accomodation of Students
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...