Codevs 5564 Tata pick apples 2

Source: Internet
Author: User

5564 Tata pick apples 2

time limit: 1 s space limit: 16000 KB title level: Silver

Title Description Description

Tata has been high enough to pick all the apples, but he has limited power, the maximum quality of q kg, there are k apples, each Apple has its own value and quality, please help Tata see how to pick can be the most valuable.

Enter a description input Description

Two integers q,k, which represent the maximum withstand, the number of apples.

The following K-lines, two integers w,v, represent the quality and value of each apple.

outputs description output Description

Outputting an integer represents the maximum benefit.

sample input to sample

10 3

5 20

3 15

8 29

Sample output Sample outputs

35

data size & Hint

For 100% data q≤100 k≤1000 v,w≤100

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 intm,n,w[1005],v[1005],f[ the];6 intMain ()7 {8scanf"%d%d",&m,&n);9      for(intI=1; i<=n;i++)Tenscanf"%d%d",&w[i],&v[i]); One      for(intI=1; i<=n;i++){ A          for(intj=m;j>=w[i];j--){ -F[j]=max (f[j],f[j-w[i]]+v[i]); -         } the     }   -printf"%d", F[m]); -     return 0; -}

Codevs 5564 Tata pick apples 2

Related Article

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.