题目传送门:P2871 [USACO07DEC]手链Charm Bracelet

题目描述

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

第一行:物品个数N和背包大小M

第二行至第N+1行:第i个物品的重量C[i]和价值W[i]

输出格式:

* 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<bits/stdc++.h>
using namespace std;
const int N = ;
const int M = ;
int c[N],w[N],dp[M]={};
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
scanf("%d%d",&c[i],&w[i]);
for (int i=;i<=n;i++)
for (int j=m;j>=c[i];j--)
dp[j]=max(dp[j],dp[j-c[i]]+w[i]);
printf("%d\n",dp[m]);
return ;
} 01背包

P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)的更多相关文章

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

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

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

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

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

  4. POJ 3624 Charm Bracelet(01背包模板题)

    题目链接 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52318   Accepted: 21912 Descriptio ...

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

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

  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

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

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

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

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

随机推荐

  1. hdu 1286 找新朋友 (容斥原理 || 欧拉函数)

    Problem - 1286 用容斥原理做的代码: #include <cstdio> #include <iostream> #include <algorithm&g ...

  2. vue4——把输入框的内容添加到页面(简单留言板)

    文章地址:https://www.cnblogs.com/sandraryan/ vue最最最简单的demo(记得引入) 实例化一个vue,绑定#app的元素,要渲染的数组arr作为data. 把ar ...

  3. H3C 物理层

  4. mysql-python安装

    操作系统:ubuntu16.04-gnome 首先要安装mysql数据 sudo apt install mysql-server 我们使用pip进行安装第三方模块 系统python版本为2.7.12 ...

  5. Vue2.0做的项目在IE下面打开一片空白?

    解决方式:安装 "babel-polyfill" 即可. 命令:cnpm install --save-dev babel-polyfill 在入口main.js文件引入:impo ...

  6. linux主编号的动态分配

    一些主设备编号是静态分派给最普通的设备的. 一个这些设备的列表在内核源码树的 Documentation/devices.txt 中. 分配给你的新驱动使用一个已经分配的静态编号的机会 很小, 但是, ...

  7. Mail.Ru Cup 2018 Round 2 B. Alice and Hairdresser (bitset<> or 其他)

    传送门 题意: 给出你序列 a,在序列 a 上执行两种操作: ① 0 :查询有多少连续的片段[L,...,R],满足 a[L,...,R] > l: ② 1 p d :将第 p 个数增加 d: ...

  8. P1077 子串乘积正负分类

    题目描述 给你一个序列包含 \(n\) 个元素的序列 \(a_1, a_2, \dots , a_n\) (每个元素 \(a_i \ne 0\)). 你需要计算如下两个值: 有多少对数 \((l, r ...

  9. 2018-6-15-win10-uwp-xaml-绑定接口

    title author date CreateTime categories win10 uwp xaml 绑定接口 lindexi 2018-6-15 21:7:19 +0800 2018-2-1 ...

  10. vue-learning:23 - js - leftcycle hooks

    vue 生命周期钩子函数 每一个Vue实例在创建时都需要经过一系列初始化.根据vue实例化过程中执行的逻辑,可以分为5个阶段: 初始化阶段 模板编译阶段 虚拟DOM挂载阶段 响应更新阶段 卸载阶段 这 ...