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<algorithm>
#include<string>
#include<iostream>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
struct asd
{
    int s,e;
};
vector<asd>a[1000001];
int dp[1000001];
int main()
{
    int n,m,r;
    scanf("%d%d%d",&n,&m,&r);
    for(int i=0; i<m; ++i)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        a[y].push_back((asd)
        {
            x,z
        });
    }
    for(int i=1; i<=n; ++i)
    {
        for(int j=0; j<a[i].size(); ++j)
        {
           int e=a[i][j].e;
           int s=a[i][j].s;
           dp[i]=max(dp[i],e);
           dp[i]=max(dp[i],dp[s-r]+e);
        }
        dp[i]=max(dp[i],dp[i-1]);
    }
    printf("%d\n",dp[n]);
    return 0;
}

时间: 2024-08-27 02:46:56

POJ3616 Milking Time 简单DP的相关文章

POJ 3616 Milking Time 简单DP

题目链接:http://poj.org/problem?id=3616 题目大意:M个区间,每个区间一个对应一个效率值-多少升牛奶,区间可能重复,现要求取出来一些区间,要求是区间间隔不能小于R,问所能得到的牛奶量的最大值. 解题思路:决策:当前区间用或者不用.区间个数M≤1000,因此直接双循环递推即可. dp[i]:=选第i个区间情况下前i个区间能获得的牛奶最大值 dp[i] = max(dp[i], dp[j] + a[i].eff) a[j].end + r <= a[i].start 代

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(状态转移方程,类似LIS)

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

POJ 3250 Bad Hair Day 简单DP 好题

Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a sp

hdu1207 汉诺塔II 简单dp

本文出自:http://blog.csdn.net/svitter 题意:汉诺塔,多了一根柱子,问你寻找最快的移动次数. dp [ n ] = dp [ n - j ] * 2 + pow( 2, j ) - 1; 就是把j个汉诺塔移到一根上dp[ n - j ],然后就是普通的汉诺塔问题,即2^n - 1次移动, 然后把剩下的移动过去dp [ n - j ]. 注意pow(2, j )可能超出long long int范围.写二的次方的时候也可用移位算法. #include <iostream

POJ1088:滑雪(简单dp)

题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一下序,因为只能高度递减才能滑行.之后就很简单了,就是简单DP. 即:要求的滑坡是一条节点递减并依次相邻的最长路径,可以先根据高度将所有的点进行排序,在i点的时候,遍历0~i-1个点(升序排序,i前面的点的高度一定小于等于i),取相邻点间的大的路径长度 代码如下: #include <iostream

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

hdu1087 简单DP

I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HD

2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题

听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到100即可 算最大GPA的时候,首先每个科目分配到60分,然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到85即可,如果还有REMAIN POINT,就FOR循环下来加到100上限即可 不会DP 阿 QAQ 过段时间得好好看DP了  =  = 于是默默的把这题标记为<水题集> //