Treasure improve screening _NOI Guide 2010 (02)

 


 

Title Description

Finally, he cracked the millennium problem. FF found a small royal treasure chamber, which is filled with countless priceless treasures ...... This small FF can be rich, quack. But the treasure here is too much, a small collection FF car seems to hold so many treasures. It seems only small FF tearful give up a part of the treasures which the FF ...... small cave where the treasures were consolidated, he found that each sample has a treasure or more pieces. He roughly estimated the value at every kind of treasure, the treasure after the start of the screening: Small FF has a maximum load of W collection vehicles, the cave has a total of n kinds of treasures, the value of each treasure for v [i], weight of w [i], each with a treasure m [i] member. FF little hope under the premise of not overloading the car collection, choose some treasures put into the collection vehicle, so that their value and maximum.

Input Format

The first line an integer N and w, respectively, represent the largest number of species carrying treasure and collect the car.

The next three integers n lines per row, where the first number indicates the i-th row of the i-type product value, the second integer represent the weight of an item class, third class integer number of items.

Output Format

Output a single integer ans, representing the maximum value of the treasures collected in the case of the acquisition vehicle is not overloaded.

Sample input and output

Input # 1
4 20
3 9 3
5 9 1
9 4 2
8 1 3
Output # 1
47

Description / Tips

For 30% of the data: n≤Σm [i] ≤10 ^ 4; 0≤W≤10 ^ 3.

To 100% of the data: n≤Σm [i] ≤10 ^ 5;

0 <w≤4*10^4:1≤n<100。

      Multiple backpack without the complexity of optimization: m (Backpack vol) $ \ sum_. 1 = {I}} ^ {n-CNT [I] $

      Optimization of binary Complexity: m (backpack volume) log ( $ \ sum_. 1 = {I}} ^ {n-CNT [I] $)

       Attach binary optimized code

     

 1 #include<bits/stdc++.h>
 2 #define re register int
 3 #define maxn 40000+5
 4 #define maxn1 1600+5
 5 
 6 
 7 using namespace std;
 8 int f[maxn],n,m;
 9 int wei[maxn1],val[maxn1];
10 int  weight,value,wcnt,cnt;
11 int main()
12 {
13     ios::sync_with_stdio(false); 
14     cin>>n>>m;
15     for(re i=1;i<=n;i++)
16     {
17         cin>>value>>weight>>wcnt;
18         for(re tmp=1;tmp<=wcnt;tmp<<=1)
19         {
20             val[++cnt]=value*tmp;
21             wei[cnt]=weight*tmp;
22             wcnt-=tmp;
23         }
24         if(wcnt) val[++cnt]=value*wcnt,wei[cnt]=weight*wcnt;
25     }
26     for(re i=1;i<=cnt;i++)
27     for(re j=m;j>=wei[i];j--)
28     f[j]=max(f[j],f[j-wei[i]]+val[i]); 
29     cout<<f[m];
30     return 0;
31 }
View Code

 

 

Guess you like

Origin www.cnblogs.com/3200Pheathon/p/11616039.html