【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1618
裸的01背包,注意背包的容量不是v即可。
- #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=105, oo=~0u>>1;
- int f[50005+5005], v[N], w[N], n, V;
- int main() {
- read(n); read(V);
- int mx=0;
- for1(i, 1, n) { read(v[i]); read(w[i]); mx=max(v[i], mx); }
- for1(i, 1, V+mx) f[i]=oo>>1;
- for1(i, 1, n) {
- for(int j=v[i]; j<=mx+V; ++j)
- f[j]=min(f[j], f[j-v[i]]+w[i]);
- }
- int ans=oo;
- for(int j=V; j<=mx+V; ++j) ans=min(ans, f[j]);
- print(ans);
- return 0;
- }
Description
Input
Output
Sample Input
3 2
5 3
Sample Output
FJ can buy three packages from the second supplier for a total cost of 9.
HINT
Source
【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)的更多相关文章
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )
无限背包dp.. 因为题目中说至少到 H 磅 , 我就直接把 H * 2 了.. ----------------------------------------------------------- ...
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
题目 1618: [Usaco2008 Nov]Buying Hay 购买干草 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 679 Solved: ...
- bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草【背包】
好像是完全背包吧分不清了-- 好像是把数组二维压一维的时候,01背包倒序,完全背包正序 ```cpp include include using namespace std; const int N= ...
- [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草
[BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...
- [Usaco2008 Nov]Buying Hay 购买干草[背包]
Description 约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草. 他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重 ...
- [Usaco2008 Nov]Buying Hay 购买干草
题目描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅 ...
- BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )
状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) = Σ dp( i , S - { i } ) ( i ∈ S , ...
- BZOJ 1229: [USACO2008 Nov]toy 玩具
BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
-------------------------------------------------------------------- #include<cstdio> #include ...
随机推荐
- GMM高斯混合模型 学习(2)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHpxMjAwODExMjExMDc=/font/5a6L5L2T/fontsize/400/fill/I0 ...
- ThinkPad如何修改fn键默认操作
ThinkPad如何修改fn键默认操作 ThinkPad笔记本如何修改fn键默认操作 Fn键F1-F12
- React.createRef()
概述: 引用(Refs)提供了一个获得DOM节点或者创建在render方法中的React元素的方法: 在典型的React数据流中,props是唯一的父组件与它们的子元素的通信方式.更改子元素,你需要使 ...
- java.lang.Void and void
java.lang.Void is analogous to java.lang.Integer. Integer is a way of boxing values of the primitive ...
- java反射--方法反射的基本操作
方法的反射 1)如何获取某个方法 方法的名称和方法的参数列表才能唯一决定某个方法. 2)方法反射的操作 method.invoke(对象,参数列表). 代码实例: package com.reflec ...
- 【laravel54】composer install与composer update的区别
1.基础概念: 我们需要明白laravel项目里面有2个配置文件,composer.json和composer.lock文件,前者是下载的依赖包配置文件,后者是锁定的包版本信息. 使用之前,需要cd ...
- 基于Redis的消息队列php-resque
转载:http://netstu.5iunix.net/archives/201305-835/ 最近的做一个短信群发的项目,需要用到消息队列.因此开始了我对消息队列选型的漫长路. 为什么选型会纠结呢 ...
- 那些最好的轮子 - PHP篇
转载于:http://avnpc.com/pages/best-wheels-for-php 在关于不要重复造轮子的二三事一文中,交代了一些背景和想法.本篇则完全是一些干货,列举一些我用过或者即将会用 ...
- git eclipse 不标记修改后的文件(没有图标标明)
在使用Eclipse做开发的时候,已经修改了某个文件,但是文件的图标没有明显的标示,如图: 解决上面问题的办法如下:
- 用户 'NT AUTHORITY\IUSR' 登录失败
今天在用VS20012发布XAF ASP.NET的程序时,在iis 调用SQLSERVER Express2008数据库时,总是出现错误“用户 'NT AUTHORITY\IUSR' 登录失败”,后来 ...