Charm Bracelet
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 23025   Accepted: 10358

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 the
N (1 ≤ N ≤ 3,402) available charms. 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 most once. Bessie can only support a charm bracelet whose weight is 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 maximum 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 two space-separated integers:
Wi and Di

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 6
1 4
2 6
3 12
2 7

Sample Output

23

题意:01背包
重点:01背包、动态规划
难点:动态方程
#include<cstdio>
#include<cstring>
int main()
{
int n,s,i,j,v[40000],w[40000],dp[40000];
while(scanf("%d%d",&n,&s)==2)
{
memset(v,0,sizeof(v));
memset(w,0,sizeof(w));
memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++)
{
scanf("%d%d",&w[i],&v[i]);
}
for(i=1;i<=n;i++)
for(j=s;j>=w[i];j--)
{
if(dp[j]<dp[j-w[i]]+v[i])
dp[j]=dp[j-w[i]] + v[i] ;
}
printf("%d\n",dp[s]);
}return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

poj3624Charm Bracelet的更多相关文章

  1. poj--3624--Charm Bracelet(动态规划 水题)

    Home Problem Status Contest Add Contest Statistic LOGOUT playboy307 UPDATE POJ - 3624 Charm Bracelet ...

  2. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  3. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  4. Charm Bracelet

    Charm Bracelet Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  5. D - Charm Bracelet 背包问题

      Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Pra ...

  6. POJ 2888 Magic Bracelet(Burnside引理,矩阵优化)

    Magic Bracelet Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 3731   Accepted: 1227 D ...

  7. poj 3524 Charm Bracelet(01背包)

    Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...

  8. POJ 3624 Charm Bracelet(01背包裸题)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 ...

  9. poj 2888 Magic Bracelet(Polya+矩阵快速幂)

    Magic Bracelet Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 4990   Accepted: 1610 D ...

随机推荐

  1. 用KnockoutJS实现ToDoMVC代码分析

    体验地址 Knockout 版todo web app在线体验 http://todomvc.com/examples/knockoutjs/ 源码地址 项目源码地址,此地址包含了各种JS框架实现的t ...

  2. 自定义ComboBox,简简单单实现

    private void Button_Click(object sender, RoutedEventArgs e) { Popup1.PlacementTarget = TesTextBox; P ...

  3. Windows Phone开发(37):动画之ColorAnimation

    原文:Windows Phone开发(37):动画之ColorAnimation 上一节中我们讨论了用double值进行动画处理,我们知道动画是有很多种的,今天,我向大家继续介绍一个动画类--Colo ...

  4. vs2012 它已停止工作 - 解决方案

    最近学习<Windows多媒体编程>本课程, 蛋疼, 学校原来是MFC... 然后安装vs2012.   后来又在几个插件.. 在这个问题. 开业,提示 vs2012 它已停止工作. wa ...

  5. Windows Phone开发(27):隔离存储A

    原文:Windows Phone开发(27):隔离存储A 在很多资料或书籍上都翻译为"独立存储",不过,我想了一下,决定将IsolatedStorage翻译为"隔离存储& ...

  6. elasticsearch2.2

    elasticsearch2.2 集群搭建各种坑     目前生产环境的es版本是1.0版本,需要升级到最新的2.2版本,于是在测试环境进行部署集群测试,在测试过程中遇到的坑相当多,下面详细介绍下. ...

  7. ngrok 本机代码部署外网访问神器(转)

    背景:听哥们说了个工具ngrok,可以让本机配置的web服务在外网访问,抱着将信将疑的态度试了试,发现还真的可以.下面记录下我自己的安装步骤,另外谈下自己还有些疑问的地方. 参考资料网站:http:/ ...

  8. CentOS 6 安装Oracle11g

    原创作品.从 "深蓝blog" 博客,欢迎转载,请务必注明转载如下源.否则追究其版权责任. 深蓝的blog:http://blog.csdn.net/huangyanlong/ar ...

  9. 王立平--android发育,转让eclipse可选颜色

    android:background="@android:color/white" 版权声明:本文博主原创文章.博客,未经同意不得转载.

  10. android手机SD卡中的android_secure目录

    .android_secure 是官方app2sd的产物,删了之后装到sd卡中的软件就无法使用了.里面有非常多.asec的文件,都是装到SD卡上的软件,可是一般装到sd卡中的程序被卸载了.androi ...