【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1625
太水了。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=13000;
int f[N], n, V, v, w; int main() {
read(n); read(V);
for1(i, 1, n) {
read(v); read(w);
for3(j, V, v) f[j]=max(f[j], f[j-v]+w);
}
print(f[V]);
return 0;
}
Description
贝 茜在珠宝店闲逛时,买到了一个中意的手镯。很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上。对于第i块宝石,它的重量为W_i(1 <= W_i <= 400),并且贝茜知道它在镶上手镯后能为自己增加的魅力值D_i(1 <= D_i <= 100)。由于贝茜只能忍受重量不超过M(1 <= M <= 12,880)的手镯,她可能无法把所有喜欢的宝石都镶上。 于是贝茜找到了你,告诉了你她所有宝石的属性以及她能忍受的重量,希望你能帮她计算一下,按照最合理的方案镶嵌宝石的话,她的魅力值最多能增加多少。
Input
* 第1行: 2个用空格隔开的整数:N 和 M
* 第2..N+1行: 第i+1行为2个用空格隔开的整数:W_i、D_i,分别为第i块宝石 的重量与能为贝茜增加的魅力值
Output
* 第1行: 输出1个整数,表示按照镶嵌要求,贝茜最多能增加的魅力值
Sample Input
1 4
2 6
3 12
2 7
输入说明:
贝茜收集了4块宝石,她能忍受重量最大为6的手镯。
Sample Output
输出说明:
贝茜把除了第二块宝石的其余所有宝石都镶上手镯,这样她能增加
4+12+7=23的魅力值,并且所有宝石的重量为1+2+3 <= 6,同样符合要求。
HINT
Source
【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)的更多相关文章
- bzoj 1625: [Usaco2007 Dec]宝石手镯【背包】
裸的01背包 #include<iostream> #include<cstdio> using namespace std; int c,n,w,v,f[20001]; in ...
- BZOJ 1625: [Usaco2007 Dec]宝石手镯( dp )
最裸的01背包.... --------------------------------------------------------------------- #include<cstdio ...
- [Usaco2007 Dec]宝石手镯[01背包][水]
Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...
- bzoj 1625: [Usaco2007 Dec]宝石手镯
Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...
- 1625: [Usaco2007 Dec]宝石手镯
1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 919 Solved: 618 [Submit][S ...
- bzoj1625:[Usaco2007 Dec]宝石手镯(背包dp板子)
1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1349 Solved: 954[Submit][St ...
- BZOJ-1625 宝石手镯 01背包(傻逼题)
傻逼题,懒得打,复制蛋蛋的.. 1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1076 Solved: ...
- [Usaco2007 Dec]宝石手镯
题目描述 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为W_i(1 & ...
- bzoj1625 [Usaco2007 Dec]宝石手镯
01背包 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring& ...
随机推荐
- xftp Initialize Flexnet Service failed / Error code: 50003
xftp Initialize Flexnet Service failed / Error code: 50003 CreateTime--2018年5月3日15:47:05 Author:Ma ...
- 单选框input:radio
单选框 CreateTime--2017年5月15日11:40:04 Author:Marydon 四.单选框 (一)语法 <input type="radio"/> ...
- JDBC 元数据信息 getMetaData()
数据库元数据信息: import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.SQLExcept ...
- 转:sock_ev——linux平台socket事件框架(uri地址的解析) .
在第一篇中,已经说明,传递的socket地址采取以下形式: [cpp] view plaincopyprint?stream://192.168.2.10:8080 dgram://192.168 ...
- ubuntu 14.04为/检查磁盘时发生严重错误的解决方法
http://jingyan.baidu.com/article/0aa22375bbffbe88cc0d6419.html
- 非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)
非变动性算法代码分析与示例: 一.for_each C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // TEMPLATE FUNCTION for_eac ...
- string 类简介和例程
一.标准库string类型 string类型支持长度可变的字符串,C++标准库将负责管理与存储字符相关的内存,以及提供各种有用的操作 ,在VC中直接F1查看 template < class C ...
- Android自己定义截屏功能,相似QQ截屏
由于公司业务需求 须要对一个屏幕进行截屏.但自带的截屏功能是远远不够项目的功能需求 ,我们是做一个画板软件 .须要的像QQ那样截屏之后 ,能够看到我们自己定义的工具.有画笔,button等等 .and ...
- Docker背景介绍
背景介绍 Docker是PasS提供商DoctCloud开源的一个基于LXC的高级容器引擎,源代码托管在Github上,基于go语言并遵从Apache2.0协议开源.Docker近期非常火热,无论是从 ...
- 分享几个linux系统版本的查看命令
发布:theboy 来源:net [大 中 小] 查看linux系统版本的命令 有如下命令可供参考: # lsb_release -a LSB Version: :core-3.1-ia ...