题目描述

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.

有N件物品和一个容量为V的背包。第i件物品的重量是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的重量总和不超过背包容量,且价值总和最大。

输入输出格式

输入格式:

  • 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

输出格式:

  • Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints

输入输出样例

输入样例#1:

4 6
1 4
2 6
3 12
2 7
输出样例#1:

23

代码
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
],d[],f[];
int main()
{
    scanf("%d%d",&n,&v);
    ;i<=n;i++)
    {
        scanf("%d%d",&d[i],&c[i]);
    }
    ;i<=n;i++)
      for(int m=v;m>=d[i];m--)
        f[m]=max(f[m],f[m-d[i]]+c[i]);
    printf("%d",f[v]);
    ;
}
 

洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包的更多相关文章

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

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

  2. 洛谷——P2871 [USACO07DEC]手链Charm Bracelet

    https://www.luogu.org/problem/show?pid=2871 题目描述 Bessie has gone to the mall's jewelry store and spi ...

  3. 洛谷 P2871 [USACO07DEC]手链Charm Bracelet 题解

    题目传送门 这道题明显就是个01背包.所以直接套模板就好啦. #include<bits/stdc++.h> #define MAXN 30000 using namespace std; ...

  4. P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)

    题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...

  5. bzoj1625 / P2871 [USACO07DEC]手链Charm Bracelet

    P2871 [USACO07DEC]手链Charm Bracelet 裸01背包. 看到自己1年半前写的30分code.......菜的真实(捂脸) #include<iostream> ...

  6. AC日记——[USACO07DEC]手链Charm Bracelet 洛谷 P2871

    题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...

  7. P2871 [USACO07DEC]手链Charm Bracelet

    题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...

  8. 【做题笔记】P2871 [USACO07DEC]手链Charm Bracelet

    就是 01 背包.大意:给您 \(T\) 个空间大小的限制,有 \(M\) 个物品,第 \(i\) 件物品的重量为 \(c_i\) ,价值为 \(w_i\) .要求挑选一些物品,使得总空间不超过 \( ...

  9. POJ 3624 Charm Bracelet(01背包)

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

随机推荐

  1. python练习1 ——菱形打印

    具体请看链接: 链接 2018-09-29 12:51:45

  2. 1.0 python-client以及ui自动化介绍

     appium的client-----捕获元素和对元素进行操作都是在client里面去写脚本实现的,client会将你写的python脚本发送到appium server上,然后appium serv ...

  3. lo口环路问题分析

    流程如下,collecter抓取网卡lo和wlan0数据,其中lo口无数据,wlan0是笔记本上网网口,然后按自定义协议把数据包通过lo口发给后端dispatch进行分发! 这种模式下,抓包程序每经过 ...

  4. django orm 的查询条件

    Django的ORM查询操作: 查询数据库操作是一个非常重要的技术.在Django中,查询一般就是使用filter.exclude.get三个方法来实现,在调用这些方法的时候传递不同的查询条件来实现复 ...

  5. hdu2010(dfs+剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. SqlServer中截取小数位数

    方法一:convert(float,字段名) as 别名 select convert(float,round(10.123232,2)) 结果:10.12 select convert(float, ...

  7. POJ 2406 Power Strings 暴力

    emmmm 显然的是a串长度是s串长度的因数 我们可以暴力枚举因数然后暴力check #include<cstdio> #include<algorithm> #include ...

  8. 静态区间第k大 树套树解法

    然而过不去你谷的模板 思路: 值域线段树\([l,r]\)代表一棵值域在\([l,r]\)范围内的点构成的一颗平衡树 平衡树的\(BST\)权值为点在序列中的位置 查询区间第\(k\)大值时 左区间在 ...

  9. Installing Wine 1.5: configure: error: Cannot build a 32-bit program, you need to install 32-bit development libraries(转载)

    Installing Wine 1.5: configure: error: Cannot build a 32-bit program, you need to install 32-bit dev ...

  10. Windows1小时后关机命令

    shutdown -s -t 3600 1.注销当前用户 shutdown - l 该命令只能注销本机用户,对远程计算机不适用. 2.关闭本地计算机 shutdown - s 3.重启本地计算机 sh ...