题目描述

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<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的更多相关文章

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

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

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

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

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

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

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

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

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

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

  9. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

随机推荐

  1. Uva122 Trees on the level

    Background Trees are fundamental in many branches of computer science. Current state-of-the art para ...

  2. poj 1364 查分约束

    #include<stdio.h> #include<iostream> #include<stack> #include<string.h> usin ...

  3. (三)用openCV在图片上绘画标记

    1.在图片上画图(直线,矩形,圆形,多边形) import numpy as np import cv2 img = cv2.imread('watch.jpg',cv2.IMREAD_COLOR) ...

  4. rpm 命令的使用

    rpm -ivh    xv-3.10a-13.i386.rpm 在Terminal中,基本的安装指令如下: rpm -i    xv-3.10a-13.i386.rpm 如果你的连网速度足够快,也可 ...

  5. T1075 明明的随机数 codevs

    http://codevs.cn/problem/1075/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description 明明想在学校中 ...

  6. Ubuntu 16.04安装PDF阅读器FoxitReader

    下载: https://www.foxitsoftware.cn/downloads/ 安装: tar zxvf FoxitReader2.4.1.0609_Server_x64_enu_Setup. ...

  7. iOS截取视频某一帧图片(关键帧,AVAssetImageGenerator)

    获取第一帧图片 导入 AVFoundation.Framework.CoreMedia.Framework 实现代码例如以下: + (UIImage*) thumbnailImageForVideo: ...

  8. ES6 一些常用使用

    //1.解构数组 let arr1 = ['apple', 'coffee', 'cake']; let [fruit, drink, dessert] = arr1; console.log(fru ...

  9. java反射中getDeclaredMethods和getMethods的区别

    getDeclaredMethods()          返回 Method 对象的一个数组,这些对象反映此 Class 对象表示的类或接口声明的所有方法,包括公共.保护.默认(包)访问和私有方法, ...

  10. Xcode 设置图片全屏显示

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...