Charm bracelettime limit:1000msmemory limit:65536kbthis problem would be judged onPKU. Original id:3624
64-bit integer IO format: %lld Java class name: Main
Bessie have gone to the mall ' s jewelry store and spies a charm bracelet. Of course, she ' d like-to-fill it with the best charms possible from the n (1≤n ≤3,402) available charm S. Each charm I in the supplied list has a weight wi (1≤ wi ≤400), a ' desirability ' factor di (1≤ Di ≤100), and can be used at the most once. Bessie can only support a charm bracelet whose weight are no more than m (1≤ m ≤12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the MA Ximum possible sum of ratings.
Input
* Line 1:two space-separated integers: N and M* Lines 2.. N+1:line i+1 describes charm I with II space-separated integers: Wi and Di
Output
* Line 1: A single integer which is the greatest sum of charm desirabilities so can be achieved given the weight Constrai Nts
Sample Input
4 61 42 63 122 7
Sample Output
23
SourceUsaco December Silver Problem solving: 01 backpack
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intdp[12900],w[3500],d[3500],n,m;6 intMain () {7 while(~SCANF ("%d%d",&n,&m)) {8 for(inti =0; I < n; ++i)9scanf"%d%d", w+i,d+i);TenMemset (DP,0,sizeofDP); One for(inti =0; I < n; ++i) A for(intj = m; J >= W[i]; --j) -DP[J] = max (Dp[j],dp[j-w[i]) +d[i]); -printf"%d\n", Dp[m]); the } - return 0; -}
View Code
POJ 3624 Charm bracelet