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
输出格式:
- Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
输入输出样例
4 6
1 4
2 6
3 12
2 7
23 虽然是裸的背包,但是这个不能用二维,会爆
然后自己手推了一下一维的,,
貌似还能更短。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
void read(int & n)
{
char c='+';int x=;int flag=;
while(c<''||c>'')
{
c=getchar();
if(c=='-')
flag=;
}
while(c>=''&&c<='')
x=x*+(c-),c=getchar();
flag==?n=-x:n=x;
}
const int MAXN=;
int n,maxt;
struct node
{
int w;
int v;
}a[MAXN];
int dp[MAXN];
int main()
{
read(n);read(maxt);
for(int i=;i<=n;i++)
{
read(a[i].w);read(a[i].v);
}
for(int i=;i<=n;i++)
{
for(int j=maxt;j>=;j--)
{
if(a[i].w<=j)
dp[j]=max(dp[j],dp[j-a[i].w]+a[i].v);
else
dp[j]=dp[j];
}
}
cout<<dp[maxt];
return ;
}
P2871 [USACO07DEC]手链Charm Bracelet的更多相关文章
- bzoj1625 / P2871 [USACO07DEC]手链Charm Bracelet
P2871 [USACO07DEC]手链Charm Bracelet 裸01背包. 看到自己1年半前写的30分code.......菜的真实(捂脸) #include<iostream> ...
- P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)
题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...
- 洛谷——P2871 [USACO07DEC]手链Charm Bracelet
https://www.luogu.org/problem/show?pid=2871 题目描述 Bessie has gone to the mall's jewelry store and spi ...
- 洛谷 P2871 [USACO07DEC]手链Charm Bracelet 题解
题目传送门 这道题明显就是个01背包.所以直接套模板就好啦. #include<bits/stdc++.h> #define MAXN 30000 using namespace std; ...
- 【做题笔记】P2871 [USACO07DEC]手链Charm Bracelet
就是 01 背包.大意:给您 \(T\) 个空间大小的限制,有 \(M\) 个物品,第 \(i\) 件物品的重量为 \(c_i\) ,价值为 \(w_i\) .要求挑选一些物品,使得总空间不超过 \( ...
- 洛谷 P2871 [USACO07DEC]手链Charm Bracelet && 01背包模板
题目传送门 解题思路: 一维解01背包,突然发现博客里没有01背包的板子,补上 AC代码: #include<cstdio> #include<iostream> using ...
- 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 ...
- 洛谷——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 ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
随机推荐
- 【06】AngularJS 控制器
AngularJS 控制器 AngularJS 控制器 控制 AngularJS 应用程序的数据. AngularJS 控制器是常规的 JavaScript 对象. AngularJS 控制器 Ang ...
- 【BZOJ4199&UOJ131】品酒大会(后缀数组,并查集)
题意: 两杯“r相似” (r>1)的酒同时也是“1 相似”.“2 相似”.…….“(r−1) 相似”的. n<=300000 abs(a[i])<=10^9 思路:对于i,j两个后缀 ...
- JavaMail发送邮件后再通过JavaMail接收格式问题
复杂邮件发送问题 转载请标明出处!https://www.cnblogs.com/dream-saddle/p/10978113.html 关于 JavaMail 如何发送邮件这里就不赘述了,网上有很 ...
- 安装Ubuntu 16.04时出现:没有定义根文件系统,请到分区菜单修改
在安装Ubuntu 16.04时,尤其是选项空闲硬盘新建分区安装时,容易出现这种情况,这个是由于没有配置挂载点导致的,解决方法如下: 在挂在点输入“/”. 原理: Linux和Windows的文件系统 ...
- 纯CSS实现移动端常见布局——高度和宽度挂钩的秘密
纯CSS实现移动端常见布局--高度和宽度挂钩的秘密 不踩坑不回头.之前我在一个项目中大量使用css3的calc计算属性.写代码的时候真心不要太爽啊-可是在项目上线之后,才让我崩溃了,原因非常easy, ...
- Codeforces 91C Ski Base 加边求欧拉回路数量
题目链接:点击打开链接 题意: 给出n个点m条无向边的图 開始图里没有边.每次加一条边,然后输出图里欧拉回路的条数. 思路: We will count the number of ski bases ...
- 创业公司十分钟简单搭建GIT私有库
欢迎关注老码农的微信公共账号,与CSDN博客同步 一.背景 小公司.协同开发的人不多,建gitlab比較麻烦,仅仅须要在Server端建立一个简单的git共享库就OK. 二.建立仓库 Server端: ...
- UVA 11748 - Rigging Elections(dfs)
UVA 11748 - Rigging Elections option=com_onlinejudge&Itemid=8&page=show_problem&category ...
- leetcode题解||Palindrome Number问题
problem: Determine whether an integer is a palindrome. Do this without extra space. click to show sp ...
- coffeescript遍历json对象
直接给代码: headers = a:"this is a" ,b:"this is b" ,c:"this is c" exheaders ...