AcWing04 (multiple backpack board)

There N N kinds of goods and a capacity V backpack of V.

The first I I kinds of goods up to S I Si pieces, each volume is V I VI, is the value W I Wi.

Which solving the items into the backpack, can not exceed the total volume of the article capacity of the backpack, and the sum of the maximum value.
The maximum output value.

Input Format

The first line of two integers, N , V N, V, separated by spaces, each represent a kind of goods and a backpack volume.

Then there are N N rows, each row of three integers V i , W i , S i VI, Wi, Si, separated by spaces, each represents i volume of the i items, quantity and value.

Output Format

Output An integer representing the maximum value.

data range

0<N,V1000<N,V≤100
0<vi,wi,si1000<vi,wi,si≤100

SAMPLE INPUT

4 5
1 2 3
2 4 1
3 4 3
4 5 2

Sample output:

10
我的板子早已饥渴难耐了!
#include <bits/stdc++.h>
using namespace std;
int N,V;
int v[10005],w[10005],dp[100+5];
int tot=0;
int main()
{
    CIN >> N >> V;
     int I, J, K = 0 ;
     for (I = . 1 ; I <= N; I ++) // binary split 
    {
         int VV, WW, SS;
        Scanf ( " % D% D% D " , & VV, WW &, & SS);
         for (J = . 1 ; J <= SS; * = J 2 ) // note is not j * = 2 ++ J 
        {
            to ++ ;
            in [tot] = vv * j;
            w [up] = vb * j;
            ss-=j;
         } 
         if(ss)
         {
             to ++ ;
             to [tot] = vv * ss;
            and [tot] = cited * ss;
         }
    } 
    int ans=0;
    for(i=1;i<=tot;i++)
    {
        for(j=V;j>=v[i];j--)
        {
            dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
        }
     } 
     cout<<dp[V];
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/lipoicyclic/p/12381241.html