Charm Bracelet(01背包)
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
题目大意:
给定n个物品,m的最大承重,求在承重范围之内的最大的D的和。
01背包模板
#include <iostream>
#include <algorithm>
using namespace std;
int w[],d[],dp[];
int n,m;
int main()
{
cin>>n>>m;
for(int i=;i<=n;i++)
cin>>w[i]>>d[i];
for(int i=;i<=n;i++)
for(int j=m;j>=w[i];j--)
dp[j]=max(dp[j],dp[j-w[i]]+d[i]);
cout<<dp[m]<<'\n';
return ;
}
Charm Bracelet(01背包)的更多相关文章
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ...
- 洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包
题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...
- POJ 3624 Charm Bracelet(01背包模板题)
题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ...
- POJ 3624 Charm Bracelet 0-1背包
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...
- 洛谷 P2871 [USACO07DEC]手链Charm Bracelet && 01背包模板
题目传送门 解题思路: 一维解01背包,突然发现博客里没有01背包的板子,补上 AC代码: #include<cstdio> #include<iostream> using ...
- poj3642 Charm Bracelet(0-1背包)
题目意思: 给出N,M,N表示有N个物品,M表示背包的容量.接着给出每一个物品的体积和价值,求背包可以装在的最大价值. http://poj.org/problem? id=3624 题目分析: o- ...
- Charm Bracelet-POJ3624(01背包)
http://poj.org/problem?id=3624 Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- poj 3624 Charm Bracelet 01背包问题
题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. 用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...
- poj 3524 Charm Bracelet(01背包)
Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...
随机推荐
- 如何改变CSV文件的编码
通常我.csv文件的编码都不是我们想要的,比如我要把他保存为Utf-8格式的,好让我可以导入数据库,不乱码 工具/原料电脑,.csv文件方法/步骤1首先,将.csv文件保存一下.然后鼠标右击打开方式记 ...
- 当document.write 遇到外联script
先来看个例子: <!DOCTYPE html> <html> <head> <title>测试 document.write</title> ...
- K-th Number 线段树的区间第K大
http://poj.org/problem?id=2104 由于这题的时间限制不紧,所以用线段树水一水. 每个节点保存的是一个数组. 就是对应区间排好序的数组. 建树的时间复杂度需要nlogn 然后 ...
- ionic之自定义图片
一个好的app,必须都有很好的ui设计师来设计界面,增强客户的体验,表现自己本身公司的特色,但是,在ionic中有些是无法用img标签直接引入图片,只能通过设定的css之后引入css. 页面: < ...
- C#中构造函数和析构函数区别
把对象的初始化工作放在构造函数中,把清除工作放在析构函数中.当对象被创建时,构造函数被自动执行.当对象消亡时,析构函数被自动执行.这样就不用担心忘记对象的初始化和清除工作. 析构函数是由垃圾回收器控制 ...
- [ POI 2017 ] Sabota?
Description 题目链接 Solution 因为一个节点染黑了子树就都被染黑了,所以最后染黑的点集必然是一棵子树. 可以得出的结论是,如果被染黑的节点在节点 \(a\) 的子树中,而 \(a\ ...
- Bean with name 'xxxService' has been injected into other beans [xxxServiceA,xxxServiceB] in its raw version as part of a circular reference, but has eventually been wrapped
启动项目,通过@Autowired注入对象,出现循环依赖,导致项目启动失败,具体报错信息如下: Exception encountered during context initialization ...
- Android学习笔记(十八) Socket
Socket在计算机网络中的概念是指套接字,包含IP地址和端口号.在Java编程中Socket是一个类,用来实现数据传输(同样可以理解为“套接字”).传输的协议包括UDP和TCP,前者为不可靠的无连接 ...
- (转)使用Spring配置文件实现事务管理
http://blog.csdn.net/yerenyuan_pku/article/details/52886207 前面我们讲解了使用Spring注解方式来管理事务,现在我们就来学习使用Sprin ...
- Java随机产生中文昵称
有时候我们注册一个网站第一次登陆系统会产生一个随机昵称供用户选择,在项目测试阶段遇到了这个问题,因为注册时没有让用户填写昵称,于是找了两种产生随机中文昵称的方法: 代码如下 package com.u ...