Poj 3624 charm bracelet Dynamic Planning (01 backpack problem)

Source: Internet
Author: User
Charm bracelet
Time limit:1000 ms   Memory limit:65536 K
Total submissions:15203   Accepted:6950

Description

Bessie has 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
N(1 ≤N≤ 3,402) Available charms. Each charmIIn the supplied list has a weight
Wi(1 ≤Wi≤ 400), a 'inclurability 'factor
Di(1 ≤Di≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more
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 maximum possible sum of ratings.

Input

* Line 1: two space-separated integers:NAndM
* Lines 2 ..N+ 1: LineI+ 1 describes charmIWith two space-separated integers:
WiAndDi

Output

* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints

Sample Input

4 61 42 63 122 7

Sample output

23

Source

Usaco 2007 December silver

 

// Poj3624 01 backpack problem # include <stdio. h> # include <string. h>/* Note that the array must be large, and then the input does not need to judge the EOF input: 4 61 42 63 122 7 dynamic planning table: 0 1 2 3 4 5 60 0 0 0 0 0 01 0 4 4 4 4 4 42 0 4 6 10 10 10 103 0 4 6 12 16 18 22 4 0 4 7 11 13 19 23 */int w [20000], d [20000], F [20000]; int main () {int n, m; int I, j; scanf ("% d", & N, & M); memset (W, 0, sizeof (w); memset (D, 0, sizeof (d); memset (F, 0, sizeof (f )); for (I = 1; I <= N; I ++) scanf ("% d", & W [I], & D [I]); for (I = 0; I <= m; I ++) f [I] = 0; for (I = 1; I <= N; I ++) for (j = m; j> = W [I]; j --) {If (F [J] <(F [J-W [I] + d [I]) f [J] = f [J-W [I] + d [I];} printf ("% d \ n", F [m]); Return 0 ;}

 

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.