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

    约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草.
    他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号. 第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅,需要的开销为Ci(l≤Ci≤5000)美元.每个干草公司的货源都十分充足,可以卖出无限多 的干草包.    帮助约翰找到最小的开销来满足需要,即采购到至少H磅干草.

Input

    第1行输入N和日,之后N行每行输入一个Pi和Ci.

Output

 
    最小的开销.

Sample Input

2 15
3 2
5 3

Sample Output

9

FJ can buy three packages from the second supplier for a total cost of 9.

HINT

Source

【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)的更多相关文章

  1. BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )

    无限背包dp.. 因为题目中说至少到 H 磅 , 我就直接把 H * 2 了.. ----------------------------------------------------------- ...

  2. BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草

    题目 1618: [Usaco2008 Nov]Buying Hay 购买干草 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 679  Solved:  ...

  3. bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草【背包】

    好像是完全背包吧分不清了-- 好像是把数组二维压一维的时候,01背包倒序,完全背包正序 ```cpp include include using namespace std; const int N= ...

  4. [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草

    [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...

  5. [Usaco2008 Nov]Buying Hay 购买干草[背包]

    Description     约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草.     他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重 ...

  6. [Usaco2008 Nov]Buying Hay 购买干草

    题目描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅 ...

  7. BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )

    状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) =  Σ dp( i , S - { i } )  ( i ∈ S , ...

  8. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  9. BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )

    -------------------------------------------------------------------- #include<cstdio> #include ...

随机推荐

  1. Leet Code OJ 219. Contains Duplicate II [Difficulty: Easy]

    题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...

  2. Statusbar、Menubar、Toolbar合集

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

  3. VS下控制台执行保持(不要一闪而过)

    曾经上课的时候是用VC++6.0来学习编程的,编完打印出来的东西就直接显示在控制台上.而在Visual Studio下会出现控制台一闪而过的情况.这个问题事实上是非常好解决的.方法有多种.以下列举两种 ...

  4. 增强基本选择器[selector_3.html]

    增强基本选择器[selector_3.html] $("ul li:first") $("ul li:last") $("table tr:even& ...

  5. Linux命令-文件处理命令:touch

    touch chengshi.list 在当前目录中创建chengshi.list文件 touch /root/chengshi.list 在root目录下面创建chengshi.list文件 tou ...

  6. 用户 'NT AUTHORITY\IUSR' 登录失败

    今天在用VS20012发布XAF ASP.NET的程序时,在iis 调用SQLSERVER Express2008数据库时,总是出现错误“用户 'NT AUTHORITY\IUSR' 登录失败”,后来 ...

  7. MFC的CListCtrl双击获取单元格的行列

    首先要把ClistCtrl设置为整选中模式和网格模式 SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT); 重写方法如下: void CAl ...

  8. miniui前端绑定枚举值

    <script type="text/javascript"> var ConvertData = { DeliveryWays: function (e, cycle ...

  9. Mysql 数据库数值类型详解

    MySQL 支持所有标准SQL 中的数值类型,其中包括严格数值类型(INTEGER.SMALLINT.DECIMAL 和NUMERIC),以及近似数值数据类型(FLOAT.REAL 和DOUBLE P ...

  10. Ubuntu14.04单机版kubernetes安装指导

    转:http://dockone.io/article/950 概述本文主要讲述如何在Ubuntu系统上安装kubernetes,网络上也有许多相关的文章,感觉都不是很清晰,这里我将自己的安装实践给大 ...