https://www.luogu.org/problem/show?pid=2871

题目描述

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 <algorithm>
#include <iostream>
#include <cstdio> using namespace std; int n,m,w[],val[];
int f[]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&val[i]);
for(int i=;i<=n;i++)
for(int V=m;V>=w[i];V--)
f[V]=max(f[V],f[V-w[i]]+val[i]);
printf("%d",f[m]);
return ;
}

洛谷——P2871 [USACO07DEC]手链Charm Bracelet的更多相关文章

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

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

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

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

  3. 洛谷——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 ...

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

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

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

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

  6. P2871 [USACO07DEC]手链Charm Bracelet

    题目描述 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

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

  8. 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 ...

  9. POJ3621或洛谷2868 [USACO07DEC]观光奶牛Sightseeing Cows

    一道\(0/1\)分数规划+负环 POJ原题链接 洛谷原题链接 显然是\(0/1\)分数规划问题. 二分答案,设二分值为\(mid\). 然后对二分进行判断,我们建立新图,没有点权,设当前有向边为\( ...

随机推荐

  1. 过河 2005年NOIP全国联赛提高组(离散化+dp)

    1105 过河 2005年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description 在河上有一 ...

  2. 我的周记1——”云想衣裳花想容"

    这里记录过去一周,我学习到的,思考的,看到的,每周五发布. http 网上参考http入门协议  https://juejin.im/post/5afad7f16fb9a07abf72ac30 超文本 ...

  3. 如何读取 Json 格式文件

    Json 源文件代码: [ { "Id": "0", "Name": "书籍", "Detail": ...

  4. android UI 操作 不要在子线程中操作UI

    不管是android ,还是 ios ,请不要在子线程中操作UI,有时有些崩溃,从报错上看不出什么原因,就有可能是子线程操作了UI:切记,切记! 请放在主线程例: activity.runOnUiTh ...

  5. 执行update, insert,delete 语句, 不返回结果集,(类型化参数)

    /// <summary> /// 执行update, insert,delete 语句, 不返回结果集,(类型化参数) /// </summary> /// <para ...

  6. 从如何停掉 Promise 链说起

    在使用Promise处理一些复杂逻辑的过程中,我们有时候会想要在发生某种错误后就停止执行Promise链后面所有的代码. 然而Promise本身并没有提供这样的功能,一个操作,要么成功,要么失败,要么 ...

  7. 慕课网中网页定位导航中js相关问题总结

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  8. 关于Adaper的相关用法

    使用BaseAdapter的话需要重载四个方法: getCount getItem getItemId getView getView是用来刷新它所在的ListView的.在每一次item从屏幕外滑进 ...

  9. sql server 数据分析优化实战(一)——SQL语句优化

    前言 在我们进行数据分析的时候,首要的目标是根据业务逻辑,通过编写SQL代码得到我们想要的结果,这是毋庸置疑的.一般情况下,由于我们分析的数据量比较少,体会不出SQL语句各种写法的性能优劣,对SQL代 ...

  10. JS——属性绑定

    1.普通形式 <script> var stu = new Object(); stu.name = "ww"; console.log(stu);//{name: & ...