poj3624Charm 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的更多相关文章
- poj--3624--Charm Bracelet(动态规划 水题)
Home Problem Status Contest Add Contest Statistic LOGOUT playboy307 UPDATE POJ - 3624 Charm Bracelet ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)
Charm Bracelet POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...
- Charm Bracelet
Charm Bracelet Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- D - Charm Bracelet 背包问题
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- POJ 2888 Magic Bracelet(Burnside引理,矩阵优化)
Magic Bracelet Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 3731 Accepted: 1227 D ...
- poj 3524 Charm Bracelet(01背包)
Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...
- POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ...
- poj 2888 Magic Bracelet(Polya+矩阵快速幂)
Magic Bracelet Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 4990 Accepted: 1610 D ...
随机推荐
- 使用装饰器模式动态设置Drawable的ColorFilter
使用装饰器模式动态设置Drawable的ColorFilter 欢迎各位关注我的新浪微博:微博 转载请标明出处(kifile的博客) 非常多时候我们都希望Android控件点击的时候,有按下效果,选中 ...
- C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装
原文:C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装 要求: JDK.Mysql.Tomcat三者制作成一个安装包, 不能单独安装,安装过程不显示三者的界面, 安装完成要配置 ...
- CC2530 外部中断 提醒
#include "ioCC2530.h" #define uchar unsigned char #define led1 P1_0 #define led2 P1_ ...
- uvalive 2911 Maximum(贪心)
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...
- java 线程 新类库中的构件 countDownLatch 使用
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlhbmdydWkxOTg4/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- swift学习一:介绍,开发文档下载
在今天wwdc2014公布会上.苹果今天公布了全新的编程语言Swift以及新版Xcode.对于开发人员来说,Swift包括了非常多开发人员喜欢的功能,能够与Objective-C和C语言共同工作.Sw ...
- java大全经典的书面采访
果学网 -专注IT在线www.prismcollege.com 1.面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面.以便更充分地注意与当前目标有关的方面.抽象并 ...
- [Java] HttpClient有个古怪的stalecheck选项
打开stale check会让每次http请求额外消耗15毫秒.而且stalecheck选项缺省是打开的. 这有必要吗???? 在局域网里面调用web api service的时候会死人的. http ...
- 自己实现的Boost库中的lexical_cast随意类型转换
知道了C++的I/O设施之后.这些就变的非常easy了. 假设你常常使用,时间长了就会有感觉.这个事情是多此一举吗?就当是练习吧,知道原理之后,你会认为用起来更舒畅,更喜欢C++了. #include ...
- DateTime.Compare(t1,t2)比較两个日期大小
DateTime.Compare(t1,t2)比較两个日期大小,排前面的小,排在后面的大,比方:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...