Problem Description
Garlic king went shopping, he has a capacity of V shopping bags, and he wanted to buy nn kinds of items, each item vi known volume and importance of pi. Garlic king wanted to know how to pick items into the shopping bag, can make the items available and the degree of importance of the largest, and the volume of goods and does not exceed the capacity of shopping bags. Note supermarket unlimited number of each item.
Input format
first line of input two integers n, V (1≤n≤1,000,1≤V≤10,000).
The next n input lines of the input two integers vi and pi (1≤vi, pi≤10,000), respectively, the volume of the i-th item and the degree of importance.
Output format
output line, output an integer that represents able to buy items of utmost importance and degrees.
Sample input
. 4 20 is
. 3. 7
2. 5
. 4. 6
. 5. 9
Sample Output
50
#include<cstdio> #include<iostream> using namespace std; int main() { int n,V,v[1010],p[1010],dp[10010]; cin>>n>>V; for(int i=1;i<=n;i++){ cin>>v[i]>>p[i]; } for (int i = 1; i <= n; ++ i) for (int j = v[i]; j <= V; ++ j) dp[j] = max(dp[j - v[i]] + p[i], dp[j]); cout<<dp[V]<<endl; return 0; }