bzoj_1625_ [Usaco2007_dec]_ Gemstone Bracelet _ (01 backpack)

Source: Internet
Author: User

Describe

http://www.lydsy.com/JudgeOnline/problem.php?id=1625

01 Backpack Nude questions.

P.S. It's a water problem.

Analysis

...

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn=3500, maxw=13000;5 intn,m;6 intW[MAXN],V[MAXN],DP[MAXW];7 intMain () {8scanf"%d%d",&n,&m);9      for(intI=1; i<=n;i++) scanf ("%d%d",&w[i],&v[i]);Ten      for(intI=1; i<=n;i++) for(intj=m;j>=w[i];j--) Dp[j]=max (dp[j],dp[j-w[i]]+v[i]); Oneprintf"%d\n", Dp[m]); A     return 0; -printf"%lf\n", f[i][n+1]); -}
View Code

1625: [Usaco2007 Dec] Gemstone bangle time limit:5 Sec Memory limit:64 MB
submit:1139 solved:782
[Submit] [Status] [Discuss]

Description

When Bessie was wandering around the jewellery shop, she bought a favorite bracelet. Naturally, she wanted to choose the best ones from the N (1 <= n <= 3,402) Gems She had collected on the bracelet. For the block I gem, it weighs w_i (1 <= w_i <= 400), and Bessie knows that it can add a charm value to itself after the bracelet is inlaid d_i (1 <= d_i <= 100). Since Bessie can only tolerate bracelets that weigh no more than M (1 <= m <= 12,880), she may not be able to set all her favorite gems. So Bessie finds you, tells you all the attributes of her gems and the weight she can tolerate, and I hope you can help her calculate how much her charm will increase by the most reasonable set of gems.

Input

* Line 1th: 2 integers separated by a space: N and M

* 2nd. N+1: Section i+1 Acts 2 integers separated by spaces: w_i, D_i, respectively, the weight of the jewel of Block I and the charm value that can be added to Bessie

Output

* Line 1th: Output 1 integers, indicating that Bessie can add up to the most attractive values according to the mosaic requirements

Sample Input

4 6
1 4
2 6
3 12
2 7

Input Description:

Bessie collected 4 jewels, and she could tolerate a bracelet with a maximum weight of 6.


Sample Output

23

Output Description:

Bessie put bracelets on all the remaining gems except the second gem, so that she could increase
The charm value of the 4+12+7=23, and the weight of all gemstones is 1+2+3 <= 6, also meet the requirements.

HINT

Source

Silver

bzoj_1625_ [Usaco2007_dec]_ Gemstone Bracelet _ (01 backpack)

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.