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. Web监听器导图详解(转)

    阅读目录 Web监听器 监听器的分类 Servlet版本与Tomcat版本 getAttribute与getParameter的区别 参考 监听器是JAVA Web开发中很重要的内容,其中涉及到的知识 ...

  2. 屏蔽DataGridView控件DataError 事件提示的异常信息

    DataGridView.DataError 事件简单介绍: 出现故障.则外部数据分析或验证操作引发异常,或者.当尝试提交数据写入数据源失败. 具体信息:參见MSDN this.dgvState.Da ...

  3. 简单fcgi程序

    1.头文件 #include <fcgi_stdio.h> 2.while(FCGI_Accept()>=0)//这里进入循环,前台每请求一次fcgi服务,就循环一次 循环内处理: ...

  4. HTML 5最终确定,八年后,我们再谈谈如何改变世界

    从原:http://www.36kr.com/p/216655.html 我们第一次谈论HTML5要改变世界大概是由于乔布斯,他坚持在iOS上不兼容Flash,在Adobe统治多媒体开发的那个年代.这 ...

  5. RPC模式的Hub操作

    signalR 专题—— 第四篇 模拟RPC模式的Hub操作   在之前的文章中,我们使用的都是持久连接,但是使用持久连接的话,这种模拟socket的形式使用起来还是很不方便的,比如只有一个唯一的 O ...

  6. Arduino 数码管LED驱动 数组法

    上个样例讲到驱动LED数码管,採用一种最直接的方案,对每一个LED进行高低电平的控制,这种长处是每一个LED都是受控可检的,避免了因为短路造成的假象,但对于数字变化来说,写起来就很冗余,因此这次尝试用 ...

  7. nodeValue的兼容问题

    nodeValue获取Text或Comment元素的文本值. 在IE6.IE7.IE8中游览器会自作聪明的去掉前面的空白字符text,而其它现代游览器则会保留空白 <body> <s ...

  8. Mongodb入门——安装与配置

    作者:zhanhailiang 日期:2014-11-07 1. 安装mongodb: [root@~/wade/nodejs/nodeclub]# yum search mongodb [root@ ...

  9. 用Jstack跟踪Cpu占用率的Java线程(转)

    以下方法在centOS下执行通过:1.先定位占用cpu高的进程 top 2.使用以下命令 ps p 14766 -L -o pcpu,pid,tid,time,tname,stat,psr | sor ...

  10. JavaHTTP下载视频

    控制层类: package com.grab.video.controller; import java.io.BufferedOutputStream; import java.io.Buffere ...