【BZOJ】1606: [Usaco2008 Dec]Hay For Sale(背包)
http://www.lydsy.com/JudgeOnline/problem.php?id=1606
越来越水了T_T
这题两种做法,一个正规01背包,价值就是体积
还有一种是非正规背包,即
if(f[j-v[i]]) f[j]=1
然后从大向小扫出第一个f[i]==1的,i就是答案
越来越水了啊。。
#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=50000;
int f[N], V, v; int main() {
read(V); int n=getint();
while(n--) {
read(v);
for(int i=V; i>=v; --i)
f[i]=max(f[i], f[i-v]+v);
}
print(f[V]);
return 0;
}
Description
Input
Output
Sample Input
2
6
5
The wagon holds 7 volumetric units; three bales are offered for sale with
volumes of 2, 6, and 5 units, respectively.
Sample Output
【BZOJ】1606: [Usaco2008 Dec]Hay For Sale(背包)的更多相关文章
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
-------------------------------------------------------------------- #include<cstdio> #include ...
- 01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale
题面:P2925 [USACO08DEC]干草出售Hay For Sale 题解:无 代码: #include<cstdio> #include<cstring> #inclu ...
- bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草【01背包】
在洛谷上被卡常了一个点! 就是裸的01背包咯 为啥我在刷水题啊 #include<iostream> #include<cstdio> #include<algorith ...
- bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- BZOJ——1606: [Usaco2008 Dec]Hay For Sale 购买干草
http://www.lydsy.com/JudgeOnline/problem.php?id=1606 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1 ...
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草(动态规划)
裸的背包= =,没什么好说的= = CODE: #include<cstdio>#include<iostream>#include<algorithm>#incl ...
- 1606: [Usaco2008 Dec]Hay For Sale 购买干草
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- bzoj1606[Usaco2008 Dec]Hay For Sale 购买干草(01背包)
1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1240 Solved: 9 ...
- BZOJ1606: [Usaco2008 Dec]Hay For Sale 购买干草
1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 612 Solved: 46 ...
随机推荐
- vista/win7/win8区别
1. Vista的内核版本号是:Windows 6.0: Windows 7的内核是:Windows 6.1: Windows 8的内核是:Windows 6.2 ...
- 8个开发必备的PHP功能
做过PHP开发的程序员应该清楚,PHP中有很多内置的功能,掌握了它们,可以帮助你在做PHP开发时更加得心应手,本文将分享8个开发必备的PHP功能,个个都非常实用,希望各位PHP开发者能够掌握. 1.传 ...
- InnoDB主键设计
InnoDB是clustered-index table,因此对于InnoDB而言,主键具有特殊意义. 可以通过主键直接定位到对应的某一数据行记录的物理位置,主键索引指向对应行记录,其他索引则都指向主 ...
- Junit4测试
1.junit初级入门 2.常用注解 3.运行流程 4.测试套件使用 5.参数化设置
- Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...
- 【转】JSP中的相对路径和绝对路径
1.首先明确两个概念: 服务器路径:形如:http://192.168.0.1/的路径 Web应用路径:形如:http://192.168.0.1/yourwebapp的路径 2.关于相对路径与绝对路 ...
- CodeForces - 420A (字符对称问题)
Start Up Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- 【读书笔记】读《JavaScript模式》 - JavaScript函数常用模式
API模式:回调模式.配置对象.返回函数: 初始化模式:即时函数.即时对象初始化.初始化分支: 性能模式:备忘模式.自定义模式 //*********************** API模式 **** ...
- Android 如何让EditText不自动获取焦点
解决之道:在EditText的父级控件中找一个,设置成 android:focusable="true" android:focusableInTouchMode=&quo ...
- android之phonegap入门
利用phoneGap可以利用HTML开发安卓应用,是web app的一种,可以有效的提高开发效率,降低开发成本 . 第一步: 开发环境配置以及基本操作请参考其它文档. 新增一个名为 phoneGap ...