您的位置:首页 > 其它

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

2015-08-09 18:58 330 查看

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

Time Limit: 5 Sec Memory Limit: 64 MB

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

Silver

题解

背包DP

但体积不是V,体积>=V,所以往V后估个值即可

var
dp:array[0..100000]of longint;
a,b:array[0..50000]of longint;
n,m,ans:longint;
i,j:longint;
function min(a,b:longint):longint;
begin
if a>b
then exit(b)
else exit(a);
end;

begin
readln(n,m);
for i:=1 to n do
readln(a[i],b[i]);
for i:=1 to m*2 do
dp[i]:=1500000000;
dp[0]:=0;
for i:=1 to n do
for j:=a[i] to m*2 do
dp[j]:=min(dp[j],dp[j-a[i]]+b[i]);
ans:=dp[m];
for i:=m+1 to m*2 do
if dp[i]<ans
then ans:=dp[i];
writeln(ans);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: