题目描述

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

思路:
  裸01背包; 来,上代码:
#include <cstdio>
#include <iostream>
#include <algorithm> using namespace std; int if_z,dp[],n,m,vi,ci; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int main()
{
in(n),in(m);
while(n--)
{
in(vi),in(ci);
for(int i=m;i>=vi;i--) dp[i]=max(dp[i],dp[i-vi]+ci);
}
cout<<dp[m];
return ;
}

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

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

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

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

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

  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. 洛谷——P2871 [USACO07DEC]手链Charm Bracelet

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

  5. P2871 [USACO07DEC]手链Charm Bracelet

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

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

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

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

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

  8. AC日记——校门外的树 洛谷 P1047

    题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...

  9. AC日记——无线网络发射器选址 洛谷 P2038

    题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...

随机推荐

  1. Linux基础学习-crond系统计划任务

    系统计划任务 大部分系统管理工作都是通过定期自动执行某个脚本来完成的,那么如何定期执行某个脚本,从而实现运维的自动化,这就要借助Linux的cron功能了. 计划任务分为一次性计划任务和周期性计划任务 ...

  2. linux关于进程、内存和cpu情况

    1.load average: 2.03, 1.76, 1.80 1分钟.5分钟.15分钟平均负载 2.%Cpu(s):100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa ...

  3. EditPlus 比较完整的快捷键记录

    FileFtpUpload Ctrl+Shift+S 上传文件到FTP 服务器 FileNew Ctrl+N 新建普通的文本文档 FileNewHtml Ctrl+Shift+N 创建一个空白的 HT ...

  4. 将php数组转js数组,js如何接收PHP数组,json的用法

    首先下载下面这个文件(这是一段是别人写出来专门解析json的代码),然后引入这个文件! http://pan.baidu.com/s/1dD8qVr7 现在当我们需要用ajax与后台进行交互时,怎样将 ...

  5. LeetCode(154) Find Minimum in Rotated Sorted Array II

    题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...

  6. html-body相关标签

    一 字体标签   字体标签包含:h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub& ...

  7. 《变革之心》读后感——《Scrum实战》第2次课作业

    刚读了几篇序言.导言和第一个故事,因此读后感可能不全面,先写一下一点儿感受吧. <变革之心>讲的是组织变革,而组织变革是以个人变革为基础的,本书的观点就是在个人变革上,“目睹--感受--变 ...

  8. 解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件

    原 解决使用intellij idea开发MAVEN项目在target目录下不存在mapper.xml文件 原文章链接:https://blog.csdn.net/beauxie/article/de ...

  9. python面试题解析(前端、框架和其他)

    答: HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  10. 令人惊叹的sublime text 3 插件

    1.Chinese​Localization------语言汉化.(新手必备) 2.SublimeTmpl------打开生成模板.(新手必备) 3.SublimeCodeIntel------代码自 ...