题目传送门: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. 关于心跳ajax请求pending状态(被挂起),stalled时间过长的问题。涉及tcp连接异常。

    环境:景安快云服务器(听说很垃圾,但是公司买的,我也刚来),CentOS-6.8-x86_64,Apache,MySQL5.1,PHP5.3. 问题:现公司有一个php系统,需要重复向后台发送ajax ...

  2. 使用 Laravel-Excel 进行 CSV/EXCEL 文件读写

    https://blog.csdn.net/yiluohan0307/article/details/80229978 http://www.ptbird.cn/laravel-excel-csv.h ...

  3. 分布式TensorFlow集群local server使用详解

    通过local server理解分布式TensorFlow集群的应用与实现. ​​简介 TensorFlow从0.8版本开始,支持分布式集群,并且自带了local server方便测试. Local ...

  4. supersockets扩展服务器配置

    关键字: 扩展配置, 自定义配置, 自定义属性, GetChildConfig, 读取配置,子节点 当你使用 SuperSocket 实现 Socket 服务器的时候,不可避免的需要在配置文件中定义一 ...

  5. Laravel根据Ip获取国家,城市信息

    https://blog.csdn.net/zhezhebie/article/details/79097133 1.安装: composer require geoip2/geoip2:~2.0 2 ...

  6. [转][ASP.NET Core 3框架揭秘] 跨平台开发体验: Windows [中篇]

    我们在<上篇>利用dotnet new命令创建了一个简单的控制台程序,接下来我们将它改造成一个ASP.NET Core应用.一个ASP.NET Core应用构建在ASP.NET Core框 ...

  7. Python--day19--time模块

    时间戳转化成结构化时间: 本地时间转换成时间字符串: 时间模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块. #常用方法 1.time.sleep(secs) (线程)推 ...

  8. LRJ 3-7

    #define _CRT_SECURE_NO_WARNINGS #include <cstdio> int main() { int T; int m, n; ][]; // 4 < ...

  9. java什么是跨平台性?原理是什么?

    所谓跨平台性,是指java语言编写的程序,一次编译后,可以在多个系统平台上运行. 实现原理:Java程序是通过java虚拟机在系统平台上运行的,只要该系统可以安装相应的java虚拟机,该系统就可以运行 ...

  10. Spring Boot JPA 懒加载

    最近在使用spring jpa 的过程中经常遇到懒加载的错误:"` org.hibernate.LazyInitializationException: could not initiali ...