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