题目链接

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. 阿里巴巴Java开发手册(格式规约篇)——查自己的漏-补自己的缺

    (三) 格式规约 1. [强制]大括号的使用约定.如果是大括号内为空,则简洁地写成{}即可,不需要换行:如果是非空代码块则: 1) 左大括号前不换行.行. 2) 左大括号后换行. 3) 右大括号前换行 ...

  2. kuma docker-compose 环境试用

    当前官方暂时还没有使用docker-compose 运行kuma 的demo(太复杂没必要),但是做为一个本地的测试环境使用 docker-compose 运行下通用模式的kuma 还有比较有意义的, ...

  3. vuex传递数据的流程

    当组件修改数据的时候必须通过store.dispatch来调用actions中的方法,当actions中的方法被触发的时候通过调用commit的方法来触发mutations里面的方法,mutation ...

  4. 洛谷P3258 [JLOI]2014松鼠的新家

    题目 树上差分 树上点差分,注意会出现路径端点多记录的情况,这时需要在最后输出的时候输出子树的差分数组的和-1,而不是在处理原数据的时候减1.并且a[n]不需要糖果,最后也减去就行. #include ...

  5. nginx之TCP反向代理

    实现Nginx tcp负载均衡 Nginx在1.9.0版本开始支持tcp模式的负载均衡,在1.9.13版本开始支持udp协议的负载,udp主要用于DNS的域名解析,其配置方式和指令和http 代理类似 ...

  6. 分布式系统 与 Google

    google 论文 http://duanple.com/?p=170 google 论文与开源 http://duanple.com/?p=1096 分布式系统论文集 https://github. ...

  7. 【Gamma阶段】第一次Scrum Meeting

    冰多多团队-Gamma阶段第一次Scrum会议 工作情况 团队成员 已完成任务 待完成任务 卓培锦 推广软件,发放调查问卷 修改可移动button以及button手感反馈优化,编辑器风格切换(夜间模式 ...

  8. 把ngnix注册为linux服务 将Nginx设置为linux下的服务 并设置nginx开机启动

    一.创建服务脚本 vim /etc/init.d/nginx 脚本内容如下 #! /bin/sh# chkconfig: - 85 15 PATH=/usr/local/nginx/sbin/ DES ...

  9. C++ Map运用实例

    C++ Map运用实例 #include <map> #include <string> #include <iostream> #include <ioma ...

  10. 查找算法(2)--Binary chop--二分查找

    1. 二分查找 (1)说明 元素必须是有序的,如果是无序的则要先进行排序操作. (2)基本思想: 也称为是折半查找,属于有序查找算法.用给定值k先与中间结点的关键字比较,中间结点把线形表分成两个子表, ...