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 ...
随机推荐
- Shiro_DelegatingFilterProxy
1.DelegatingFilterProxy实际上是Filter的一个代理对象.默认情况下,Spring会到IOC容器中查找与<filter-name>对应的filter bean.也可 ...
- How Can You Tell the Difference Between LINQ Methods and Query Builder Methods?
LINQ's method syntax looks very similar to the query builder methods,except for one big difference:t ...
- HDU 2082 母函数法
#include <cstdio> #include <cstring> using namespace std; ] , dp[][]; int main() { // fr ...
- HDU 1540 区间合并线段树
题目大意: 就是给定一堆位置,进行删除还原,最后找到 t 位置上的最大连续位置 #include <cstdio> #include <cstring> #include &l ...
- [luoguP3565] [POI2014]HOT-Hotels(dfs)
传送门 三点在树上距离相等的情况只有一种,就是以某一个点为中心,三个点到这个点的距离相等. 所以直接枚举每个点作为中心,dfs这个中心的子树,根据乘法原理统计答案即可. 时间复杂度 O(n2) (n ...
- Asp.Net页面生命周期[转]
一.什么是Asp.Net页面生命周期 当我们在浏览器地址栏中输入网址,回车查看页面时,这时会向服务器端(IIS)发送一个request请求,服务器就会判断发送过来的请求页面, 完全识别 HTTP 页 ...
- 洛谷—— P2658 汽车拉力比赛
https://www.luogu.org/problem/show?pid=2658 题目描述 博艾市将要举行一场汽车拉力比赛. 赛场凹凸不平,所以被描述为M*N的网格来表示海拔高度(1≤ M,N ...
- Ubuntu 16.04安装PPA图形化管理工具Y PPA Manager
安装: sudo add-apt-repository ppa:webupd8team/y-ppa-manager sudo apt-get update sudo apt-get install y ...
- spring mvc参数校验
一.在SringMVC中使用 使用注解 1.准备校验时使用的JAR validation-api-1.0.0.GA.jar:JDK的接口: hibernate-validator-4.2.0.Fina ...
- laravel5.5更新到laravel5.7
为什么要更新呢?因为项目用的第三方后台扩展包,有很些bug,不够完美.想要一个漂亮的后台,那个后台只支持5.7. 然后,我就开始更新框架了. 修改后:"php": "&g ...