题目链接

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 52318   Accepted: 21912

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


Sample Output


AC代码(模板题)

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
int dp[N];
int s, n;//背包容积和物品数量 struct Thing
{
int w;
int v;
}list[]; void init()
{
for (int i = ; i <= s; i++)dp[i] = ;
} void package()
{
for (int i = ; i < n; i++)
{
for (int j = s; j >= list[i].w; j--)
{
dp[j] = max(dp[j], dp[j - list[i].w] + list[i].v);
}
}
} int main()
{
scanf("%d%d", &n, &s);
for (int i = ; i < n; i++)scanf("%d%d", &list[i].w, &list[i].v);
init();
package();
printf("%d", dp[s]);
return ;
}
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; struct T
{
int w, v;
}t[]; int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = ; i < n; i++)scanf("%d%d", &t[i].w, &t[i].v);
int dp[];
memset(dp, , sizeof(dp));
for (int i = ; i < n; i++)
{
for (int j = m; j >= t[i].w; j--)dp[j] = max(dp[j - t[i].w] + t[i].v, dp[j]);
}
printf("%d\n", dp[m]);
return ;
}

二刷

POJ 3624 Charm Bracelet(01背包模板题)的更多相关文章

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

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

  2. POJ 3624 Charm Bracelet 0-1背包

    传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...

  3. POJ 3624 Charm Bracelet(01背包)

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

  4. poj 3624 Charm Bracelet 01背包问题

    题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放.             用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...

  5. 洛谷 P2871 [USACO07DEC]手链Charm Bracelet && 01背包模板

    题目传送门 解题思路: 一维解01背包,突然发现博客里没有01背包的板子,补上 AC代码: #include<cstdio> #include<iostream> using ...

  6. POJ 3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Bessie has gone to the mall's jewelry store and spies a charm br ...

  7. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

  8. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  9. poj 3624 Charm Bracelet 背包DP

    Charm Bracelet Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ...

随机推荐

  1. JSE,JEE,JME三者之间有什么区别

    JAVA是一种面向对象语言由SUN公司出品 J针对不同的使用方向规划出J2SE,J2EE,J2ME三个版本 J2SE 指标准版一般用于用户学习JAVA语言的基础也是使用其他两个版本的基础主要用于编写C ...

  2. swift的类型系统

    顶级抽象:protocol 具体类型:值类型.引用类型 类型操作:扩展 其他: 范型.函数式类型:function.monand

  3. XXE(外部实体注入攻击)

    利用XXE漏洞可以进行拒绝服务攻击.文件读取.命令代码执行.SQL(XSS)注入.内外扫描端口和入侵内网站点等,内网探测和入侵是利用XXE中支持的协议进行内网主机和端口的发现,可以理解为使用XXE进行 ...

  4. springcloud_Hystrix(熔断器)

    为什么需要 Hystrix? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用(RPC).为了保证其高可用,单个服务又必须集群部署.由于网络原因或者自身的原因,服务并不能保证服 ...

  5. java之Matcher类详解

    在JDK 1.4中,Java增加了对正则表达式的支持. java与正则相关的工具主要在java.util.regex包中:此包中主要有两个类:Pattern.Matcher. Matcher  声明: ...

  6. Odds calculation required for the python strategy library

    Bet Class class strats.Bet(inp)[source] Here is an example of the expected string input on instantia ...

  7. MYSQL索引的作用和创建

    索引是查询优化最主要的方式: 查询方式: 一种是:全表扫描: 一种是:利用数据表上建立的所以进行扫描. 如:对表中name字段建立索引:则按照表中name字段进行索引排序,并为其建立指向数据表中记录所 ...

  8. cf1189解题报告

    cf1189div2解题报告 codeforces A 答案要不是一串要不就是去掉最后一个字母的两串 #include <bits/stdc++.h> #define ll long lo ...

  9. python .md5 加密

    import hashlib hash = hashlib.md5() hash.update(text.encode('utf-8')) print(hash.hexdigest())

  10. ImportError: cannot import name 'DjangoSuitConfig'

    pip3.6 install https://github.com/darklow/django-suit/tarball/v2