"Codevs 3269" hybrid backpack

Source: Internet
Author: User

Title Description Description
The backpack volume is V, gives n items, each item occupies a volume of VI, the value of WI, each item can take up to 1 pieces, or the maximum number of MI pieces (Mi > 1), or the amount of unlimited, in the total volume of the items installed under the premise of the contents of the value of the goods and the largest value of what.

Enter a description input Description
The first line two number n,v, the following n lines each row three number Vi,wi,mi represents each item's volume, the value and the quantity, Mi=1 represents the most takes one piece, mi>1 indicates to take the Mi piece, the mi=-1 indicates the quantity infinite

Outputs description Output Description
1 Number ans indicates the maximum value of the loaded item value

Sample input to sample
2 10

3 7 2

2 4-1

Sample output Sample Outputs
22

Data Size & Hint
For 100% data, V <= 200000, N <= 200

State transfer According to the number of items

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
const int MAXN = 200005;
int n,v,x,vi,wi;

int ans = 0,DP[MAXN];
    void Zopack (int vi,int WI) {for (int i = v-vi; I >= 0; I-) dp[i + VI] = MAX (dp[i + vi],dp[i] + WI);
Return 
    } void Wqpack (int vi,int WI) {for (int i = 0; I <= v-vi; i + +) Dp[i + vi] = MAX (dp[i + vi],dp[i] + WI);
Return
    } void Dcpack (int vi,int wi,int x) {if (vi * x > V) wqpack (VI,WI);
    int now = 1;
        while (now < x) {Zopack (vi * NOW,WI * now);
        X-= Now;
    Now <<= 1;
    } zopack (vi * X,WI * x);
Return
    } int main () {scanf ("%d%d", &n,&v);
        for (int i = 1; I <= n; i + +) {scanf ("%d%d%d", &vi,&wi,&x);
        if (x < 0) wqpack (VI,WI);
    else Dcpack (vi,wi,x);
    } for (int i = 0; I <= v; i + +) ans = max (ans,dp[i]); printf ("%d\n", aNS);   
return 0; }

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.