洛谷 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.

输入输出样例

输入 #1复制

2 15
3 2
5 3
输出 #1复制

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的更多相关文章

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

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

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

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

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

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

  4. bzoj1618 / P2918 [USACO08NOV]买干草Buying Hay(完全背包)

    P2918 [USACO08NOV]买干草Buying Hay 显然的完全背包 设$f[i]$为买$i$磅干草的最小代价 搞搞完全背包即可 注意到最后可能买的干草超出范围,但是价格可能更低. 于是我们 ...

  5. 洛谷 P2918 [USACO08NOV]买干草Buying Hay 题解

    P2918 [USACO08NOV]买干草Buying Hay 题目描述 Farmer John is running out of supplies and needs to purchase H ...

  6. USACO Buying Feed, II

    洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II 洛谷传送门 JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II ...

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

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

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1618 裸的01背包,注意背包的容量不是v即可. #include <cstdio> #i ...

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

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

随机推荐

  1. rest-framework框架——版本

    一.DRF版本控制介绍 随着项目更新,版本会越来越多,不能新的版本出现,旧版本就不再使用维护了.因此不同的版本会有不同的处理,且接口会返回不同的信息. API版本控制允许我们在不同的客户端之间更改行为 ...

  2. Unity 2018 Cookbook (Matt Smith 著)

    1. Displaying Data with Core UI Elements (已看) 2. Responding to User Events for Interactive UIs (已看) ...

  3. Python爬取糗事百科示例代码

    参考链接:http://python.jobbole.com/81351/#comment-93968 主要参考自伯乐在线的内容,但是该链接博客下的源码部分的正则表达式部分应该是有问题,试了好几次,没 ...

  4. C# 匿名回调方法在循环体中使用的注意事项

    今天在做AVG工具的选择分支功能时发现了一个问题,先把代码贴上来: private void SelectionParse(string value) { string[] ss = value.Sp ...

  5. Docker系列之学习笔记

    一.Docker简介 1.1.Docker架构 Docker 使用客户端-服务器 (C/S) 架构模式,分为Docker守护进程和客户端,Docker 客户端,实际上是 docker 的二进制程序,D ...

  6. H3C S12508单板卡 通过bootware升级software版本

    H3C S12508单板卡 通过bootware升级software版本 案例:S12508更换主控板LST1MRPNC1 ,该板卡状态为Slave状态: 设备状态:S12508共2台做了堆叠,共含4 ...

  7. 从零开始实现放置游戏(六)——实现后台管理系统(4)Excel批量导入

    前面我们已经实现了在后台管理系统中,对配置数据的增删查改.但每次添加只能添加一条数据,实际生产中,大量数据通过手工一条一条添加不太现实.本章我们就实现通过Excel导入配置数据的功能.这里我们还是以地 ...

  8. SetApartmentState(ApartmentState state).Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process

    System.Threading.ThreadStateException: 'Current thread must be set to single thread apartment (STA) ...

  9. WPF ControlTemplate,DataTemplate

    The Control Template defines the visual appearance of a control. All of the UI elements have some ki ...

  10. WPF中绘图(含调用GDI+)

    private void DrawStuff() { // //if (buffer == null) //{ // buffer = new RenderTargetBitmap((int)Back ...