"Problem description"
In Harry Potter and the Deathly Hallows, Harry Potter them to flee together and now has a lot of things to put into Hermione's bag, but the size of the bag is limited, so we can only put very important items in it, Now give the number, volume, value of the item, I hope you can figure out how to make the backpack the most valuable combination, and output this value, Hermione will be very grateful to you.
"Input File" (hallows.in)
(1) The first line has 2 integers, the number of items n and the backpack loading volume V.
(2) 2 rows to n+1 lines of 3 integers per line, for the number of items i m, Volume W, value S.
"Output File" (hallows.out)
The output file Hallows.out contains only one integer, which is the sum of the maximum item value that can be obtained.
"Input Sample"
2 10
3 4 3
2 2 5
"Output Example"
13
Comments
Choose the first one, the second two.
The result is 3*1+5*2=13
"Data Size"
For 30% of data
1<=v<=500
1<=n<=2000
1<=m<=10
1<=w<=20
1<=s<=100
For 100% of data
1<=v<=500
1<=n<=2000
1<=m<=5000
1<=w<=20
1<=s<=100
/*Backpack Water Problem*/#include<cstdio>#include<iostream>#defineN 40010#defineM 510using namespacestd;intw[n],v[n],f[m],n,m,cnt;intMain () {Freopen ("jh.in","R", stdin); scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) { intnum,ww,vv,p=0; scanf ("%d%d%d",&num,&ww,&vv); while(Num-(1<<P) >=0) {w[++cnt]=ww* (1<<p); V[CNT]=vv* (1<<p); Num-=(1<<P);p + +; } if(num) {w[++cnt]=ww*num; V[CNT]=vv*num; } } for(intI=1; i<=cnt;i++) for(intj=m;j>=w[i];j--) F[j]=max (f[j-w[i]]+V[i],f[j]); printf ("%d", F[m]); return 0;}View Code
Ready to flee