Ready to flee

Source: Internet
Author: User

"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&LT;&LT;P) >=0) {w[++cnt]=ww* (1<<p); V[CNT]=vv* (1<<p); Num-=(1&LT;&LT;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

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.