USACO Buying Hay
洛谷 P2918 [USACO08NOV]买干草Buying Hay
https://www.luogu.org/problem/P2918
JDOJ 2592: USACO 2008 Nov Silver 1.Buying Hay
https://neooj.com:8082/oldoj/problem.php?id=2592
题目描述
Farmer John is running out of supplies and needs to purchase H (1 <= H <= 50,000) pounds of hay for his cows.
He knows N (1 <= N <= 100) hay suppliers conveniently numbered 1..N. Supplier i sells packages that contain P_i (1 <= P_i <= 5,000) pounds of hay at a cost of C_i (1 <= C_i <= 5,000) dollars. Each supplier has an unlimited number of packages available, and the packages must be bought whole.
Help FJ by finding the minimum cost necessary to purchase at least H pounds of hay.
约翰的干草库存已经告罄,他打算为奶牛们采购H(1 \leq H \leq 50000)H(1≤H≤50000)镑干草.
他知道N(1 \leq N\leq 100)N(1≤N≤100)个干草公司,现在用11到NN给它们编号.第ii公司卖的干草包重量 为P_i (1 \leq P_i \leq 5,000)Pi(1≤Pi≤5,000) 磅,需要的开销为C_i (1 \leq C_i \leq 5,000)Ci(1≤Ci≤5,000) 美元.每个干草公司的货源都十分充足, 可以卖出无限多的干草包.
帮助约翰找到最小的开销来满足需要,即采购到至少HH镑干草.
输入格式
* Line 1: Two space-separated integers: N and H
* Lines 2..N+1: Line i+1 contains two space-separated integers: P_i and C_i
输出格式
* Line 1: A single integer representing the minimum cost FJ needs to pay to obtain at least H pounds of hay.
输入输出样例
2 15
3 2
5 3
9
说明/提示
FJ can buy three packages from the second supplier for a total cost of 9.
裸的完全背包。
出了一些小bug。
我FSW以后要是再用memset置数组,我当场吃翔。
这道题一个坑点就是,你可以多买一些草,不一定非得是h,因为公司提供的是干草包,而干草包最多有5000,所以需要把范围多置5000,这是细节。
然后就是纯套完全背包模板。
祝大家刷题愉快。
#include<cstdio>
#include<algorithm>
using namespace std;
int n,h,ans=1e9;//n,种类数,h,总体积
int m[],w[];
int dp[];
int main()
{
for(int i=;i<=;i++)
dp[i]=1e9;
scanf("%d%d",&n,&h);
for(int i=;i<=n;i++)
scanf("%d%d",&m[i],&w[i]);
for(int i=;i<=n;i++)
for(int j=m[i];j<=h+;j++)
dp[j]=min(dp[j],dp[j-m[i]]+w[i]);
for(int i=h;i<=h+;i++)
ans=min(ans,dp[i]);
printf("%d",ans);
return ;
}
USACO Buying Hay的更多相关文章
- [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草
[BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...
- 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: ...
- bzoj1618 / P2918 [USACO08NOV]买干草Buying Hay(完全背包)
P2918 [USACO08NOV]买干草Buying Hay 显然的完全背包 设$f[i]$为买$i$磅干草的最小代价 搞搞完全背包即可 注意到最后可能买的干草超出范围,但是价格可能更低. 于是我们 ...
- 洛谷 P2918 [USACO08NOV]买干草Buying Hay 题解
P2918 [USACO08NOV]买干草Buying Hay 题目描述 Farmer John is running out of supplies and needs to purchase H ...
- USACO Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II 洛谷传送门 JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II ...
- [Usaco2008 Nov]Buying Hay 购买干草[背包]
Description 约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草. 他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重 ...
- 【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1618 裸的01背包,注意背包的容量不是v即可. #include <cstdio> #i ...
- bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草【背包】
好像是完全背包吧分不清了-- 好像是把数组二维压一维的时候,01背包倒序,完全背包正序 ```cpp include include using namespace std; const int N= ...
随机推荐
- c#数组没有Remove方法,转换为list,再使用Remove方法(例如数组 a,b,c 去除b 只剩a c)
c#数组没有Remove方法,转换为list再移除,因为list自带Remove方法 string aaa=a,b,c; var array=aaa.Split(',');// 数组 List ...
- oracle序列相关
一. oracle中如何实现一列的规律增长呢(通常是指number类型的列)? 这就需要借助序列来实现了; 1. 什么是序列? 可以理解为序列是一组sql语法创建出来的函数, 该函数中定义 好 ...
- ORB-SLAM2 地图保存
一.简介 在ORB-SLAM2的System.h文件中,有这样一句话:// TODO: Save/Load functions,让读者自己实现地图的保存与加载功能.其实在应用过程中很多场合同样需要先保 ...
- [ZJOI2019] 开关 (一种扩展性较高的做法)
[ZJOI2019] 开关 (一种扩展性较高的做法) 题意: 有n个开关,一开始状态都为关闭.每次随机选出一个开关将其状态改变,选出第i个开关的概率为${ p_i \over \sum_{i=1}^n ...
- 【Java语言特性学习之六】扩展知识点
一.SPI机制 二.注解处理机制 三.java native关键字 https://www.cnblogs.com/KingIceMou/p/7239668.html
- 在windows下使用VirtualEnv建立flask项目
1.系统中安装VirtualEnv 在安装完Python后,自带的有pip或easy_install工具,可进行VirtualEnv的安装 pip install virtualenv 2.构造项目, ...
- flexible.js 布局详解
原文链接:http://caibaojian.com/flexible-js.html 本文讲的通过flexible.js实现了rem自适应,有了flexible.js,我们就不必再为移动端各种设备兼 ...
- MySQL使用crontab定时备份不执行问题
在使用crontab定时备份数据库时,发现并没有执行备份命令. 下面是定时备份的代码: 30 1 * * * /usr/local/mysql/bin/mysqldump --defaults-ext ...
- java架构之路(mysql底层原理)Mysql之Explain使用详解
上篇博客,我们详细的说明了mysql的索引存储结构,也就是我们的B+tree的变种,是一个带有双向链表的B+tree.那么我今天来详细研究一下,怎么使用索引和怎么查看索引的使用情况. 我们先来简单的建 ...
- [翻译]微软 Build 2019 正式宣布 .NET 5
原文: Introducing .NET 5 今天,我们宣布 .NET Core 3.0 之后的下一个版本将是 .NET 5 .这将是 .NET 系列的下一个重要版本. 将来只会有一个 .NET ,您 ...