[BZOJ1618] [Usaco2008 Nov]Buying Hay 购买干草
2015-08-09 18:58
330 查看
1618: [Usaco2008 Nov]Buying Hay 购买干草
Time Limit: 5 Sec Memory Limit: 64 MBDescription
约翰的干草库存已经告罄,他打算为奶牛们采购日(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 153 2
5 3
Sample Output
9FJ 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.
相关文章推荐
- 【网络流】 POJ 2125 Destroying The Graph
- Java注解之常用注解
- 【整理】C语言中常见的字符串操作函数
- 在 Exchange 服务器上的操作系统中的防病毒软件
- 中值滤波去除噪点项目设计书
- 并查集算法介绍
- GestureDetector你需要知道的一点
- Java程序设计之链表结构
- crontab 详解
- Java集合类总结
- Java基础学习总结---------IO概述(1)
- Qt杂记
- Leetcode# 112 Path Sum
- Jena API 使用介绍
- rman备份脚本
- linux调优工具使用
- iOS crash log 解析
- 宝贵数据集——用于数据挖掘、机器学习、文本挖掘
- 将字符串追加用的函数
- codeforece 18c