zoukankan      html  css  js  c++  java
  • DP 之 poj 3616

    定义:dp[i] := 在已排好序的list的第 i 次John可从Bessie获取的最大牛奶量
    dp[i] = max(dp[i], myNode[i].myvalue + dp[j]);
    // 条件是: myNode[j].myend + R <= myNode[i].mystart (两重循环解决)
     1 //  [4/4/2014 Sjm]
     2 #include <iostream>
     3 #include <cstdio>
     4 #include <algorithm>
     5 using namespace std;
     6 const int MAX_M = 1000, MAX_N = 1000001;
     7 int N, M, R;
     8 struct node {
     9     int mystart, myend, myvalue;
    10 };
    11 bool Cmp(const node n1, const node n2) {
    12     if (n1.mystart == n2.mystart) return n1.myend < n2.myend;
    13     else return n1.mystart < n2.mystart;
    14 }
    15 node myNode[MAX_M];
    16 int dp[MAX_M];
    17 
    18 int Solve()
    19 {
    20     for (int i = 0; i < M; i++)
    21         for (int j = 0; j < i; j++){
    22             if (myNode[j].myend + R <= myNode[i].mystart){
    23                 dp[i] = max(dp[i], myNode[i].myvalue + dp[j]);
    24             }
    25         }
    26     int ans = 0;
    27     for (int i = 0; i < M; i++)
    28         ans = max(ans, dp[i]);
    29     return ans;
    30 }
    31 
    32 int main()
    33 {
    34     //freopen("input.txt", "r", stdin);
    35     //freopen("output.txt", "w", stdout);
    36     scanf("%d%d%d", &N, &M, &R);
    37     for (int i = 0; i < M; i++) {
    38         scanf("%d%d%d", &myNode[i].mystart, &myNode[i].myend, &myNode[i].myvalue);
    39     }
    40     sort(myNode, myNode + M, Cmp);
    41     for (int i = 0; i < M; i++)
    42         dp[i] = myNode[i].myvalue;
    43     printf("%d
    ", Solve());
    44     return 0;
    45 }


  • 相关阅读:
    【洛谷P1119】灾后重建
    【洛谷P1462】通往奥格瑞玛的道路
    【洛谷P1991】无线通讯网
    poj 2892(二分+树状数组)
    hdu 1541(树状数组)
    hdu 5059(模拟)
    hdu 5056(尺取法思路题)
    poj 2100(尺取法)
    hdu 2739(尺取法)
    poj 3320(尺取法)
  • 原文地址:https://www.cnblogs.com/shijianming/p/4140867.html
Copyright © 2011-2022 走看看