"Algorithm" full backpack

Source: Internet
Author: User

There are n items and a backpack with a capacity of M, with unlimited pieces available for each item. The volume of the article I is weight, and the value is values. The solution of which items are loaded into the backpack allows the volume of these items to be no more than the backpack capacity, and the value of the largest sum.
1 //"n" is the number of kinds.2 //"M" is the capacity of the bag.3 //w[]:weight, V[]:value.4 5  for(intI=1; I <= N; i++) {6      for(intVal=0; Val<=m; val++) {7         if(Val >= w[i]) dp[val] = max (Dp[val], dp[Val-w[i]]+v[i]);8     } 9}

"Algorithm" full backpack

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.