NYOJ-860 See 01 Backpack again

Source: Internet
Author: User

See also 01 backpack time limit: ms | Memory limit:65535 KB Difficulty:3
Describe
there are n weights and values for the items of WI and VI , from which the total weight of items not exceeding W is chosen, and the maximum value of the sum of the items in all selection options is obtained. 1 <= N <=100 1 <= wi <= 10^7 1 <= vi <= 1 <= W <= 10^9
Input
multiple sets of test data. Each set of test data is entered in the first row, N and W, followed by n lines, each line entered two numbers, representing the first item of WI and VI.
Output
meet the maximum value of test instructions, one row per group of test data.
Sample input
4 52 31 23 42 2
Sample output
7
Source
Drift Friendship Series
Uploaded by
tc_ Zhang Friendship
#include <stdio.h>#include<algorithm>using namespacestd;intdp[10001],wi[101],vi[101];Const intinf=0x6fffffff;//0x3f3f3f3f;//;intMain () {intn,w;  while(~SCANF ("%d%d",&n,&W)) {        intsum=0, I,v;  for(i=1; i<=n;++i) {scanf ("%d%d",&wi[i],&Vi[i]); Sum+=Vi[i]; }         for(i=1; i<=sum;++i) dp[i]=INF; dp[0]=0;  for(i=1; i<=n;++i) {             for(v=sum;v>=vi[i];--v) {Dp[v]=min (dp[v-vi[i]]+Wi[i],dp[v]); }        }         for(i=sum;i>=0;--i) {            if(dp[i]<=W) Break; } printf ("%d\n", i); }    return 0;}

NYOJ-860 See 01 Backpack again

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.