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

4 6
1 4
2 6
3 12
2 7

输入说明:

贝茜收集了4块宝石,她能忍受重量最大为6的手镯。

Sample Output

23

输出说明:

贝茜把除了第二块宝石的其余所有宝石都镶上手镯,这样她能增加
4+12+7=23的魅力值,并且所有宝石的重量为1+2+3 <= 6,同样符合要求。

HINT

Source

【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)的更多相关文章

  1. bzoj 1625: [Usaco2007 Dec]宝石手镯【背包】

    裸的01背包 #include<iostream> #include<cstdio> using namespace std; int c,n,w,v,f[20001]; in ...

  2. BZOJ 1625: [Usaco2007 Dec]宝石手镯( dp )

    最裸的01背包.... --------------------------------------------------------------------- #include<cstdio ...

  3. [Usaco2007 Dec]宝石手镯[01背包][水]

    Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...

  4. bzoj 1625: [Usaco2007 Dec]宝石手镯

    Description 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为 ...

  5. 1625: [Usaco2007 Dec]宝石手镯

    1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 919  Solved: 618 [Submit][S ...

  6. bzoj1625:[Usaco2007 Dec]宝石手镯(背包dp板子)

    1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1349  Solved: 954[Submit][St ...

  7. BZOJ-1625 宝石手镯 01背包(傻逼题)

    傻逼题,懒得打,复制蛋蛋的.. 1625: [Usaco2007 Dec]宝石手镯 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1076 Solved: ...

  8. [Usaco2007 Dec]宝石手镯

    题目描述 贝茜在珠宝店闲逛时,买到了一个中意的手镯.很自然地,她想从她收集的 N(1 <= N <= 3,402)块宝石中选出最好的那些镶在手镯上.对于第i块宝石,它的重量为W_i(1 & ...

  9. bzoj1625 [Usaco2007 Dec]宝石手镯

    01背包 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring& ...

随机推荐

  1. Statusbar、Menubar、Toolbar合集

    In the last example of this section, we create a menubar, a toolbar and a statusbar. We also create ...

  2. Python 创建特殊元组tuple

    创建1个元素的tuple  (1,) 创建单元素tupletuple和list一样,可以包含 0 个.1个和任意多个元素.包含多个元素的 tuple,前面我们已经创建过了.包含 0 个元素的 tupl ...

  3. Java注解总结

    注解是Spring和Mybatis框架所大量使用的技术,要想掌握框架相关技术,注解是必须要掌握的. 掌握注解的优势: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需 ...

  4. Python-try except else finally有return时执行顺序探究

    学习python或者其他有异常控制的编程语 言, 大家很有可能说try except finally(try catch finally)的执行很简单,无非就是有异常的话执行except, final ...

  5. 【LeetCode】81. Search in Rotated Sorted Array II (2 solutions)

    Search in Rotated Sorted Array II Follow up for "Search in Rotated Sorted Array":What if d ...

  6. 【LeetCode】102. Binary Tree Level Order Traversal (2 solutions)

    Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes ...

  7. javascript通用函数库

    /* -------------- 函数检索 -------------- trim函数:                         trim() lTrim() rTrim() 校验字符串是否 ...

  8. phpstorm设置断点调试

    环境是:wamp PHP Version: 5.5.12 网上的教程很多,我自己按照教程操作,实现了断点调试,下面是我设置断点调试的步骤 1.修改配置文件php.ini,按下面修改(位置在最后) ; ...

  9. python基础篇---列表---知识点回顾

    列表:数据的集合,里面可以放任何的数据类型,可进行增删改查等操作 有序列表功能(index是列表的索引值): ①创建:用  []  表示,里面添加元素,如n2 = [1,2,4,5,5]:    或者 ...

  10. 整理 pandas 常用函数

    1. df.head(n): 显示数据前n行,不指定n,df.head则会显示所有的行 2. df.columns.values获取所有列索引的名称 3. df.column_name: 直接获取列c ...