HDU 3466 Proud Merchants

Source: Internet
Author: User
Tags sort

This topic really opened the eye, very strong, just started directly to the Q sort, direct WA, it seems that the answer to God's cattle after understanding to follow the q-p to arrange, think carefully, consider the special situation if the time is ordinary 01 backpack, according to Q row is definitely a problem, But according to Q-p is actually in the array with the new process in the number of affected States, the larger the q-p, then the number of the influence of the later state, but the specific mathematical proof really does not, just with a special example of their own to deduce a few times ...

Title Link: https://vjudge.net/problem/HDU-3466

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 505;
int cntn, CNTM;
int dp[5005];

struct Node {
    int p, q, v;
    Node (int p=0, int q=0, int v=0): P (P), q (q), V (v) {} 
    bool operator < (const node& RHS) Const {
        return q-p < RHS.Q-RHS.P;
    }
} NODE[MAXN];

void Solve () {for
    (int i = 1; I <= cntn; i++) {for
        (int j = Cntm; J >= node[i].q; j--)
            dp[j] = Max (Dp[j], dp[j-node[i].p]+node[i].v);
    }
    printf ("%d\n", Dp[cntm]);
}

int main () {while
    (scanf ("%d%d", &CNTN, &CNTM)! = EOF) {
        memset (dp,0,sizeof (DP));
        memset (node,0,sizeof (node));
        for (int i = 1; I <= cntn; i++)
            scanf ("%d%d%d", &NODE[I].P, &NODE[I].Q, &NODE[I].V);
        Sort (node+1, node+cntn+1);
        Solve ();
    }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.