BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
题目
1618: [Usaco2008 Nov]Buying Hay 购买干草
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 679 Solved: 347
[Submit][Status]
Description
Input
Output
Sample Input
3 2
5 3
Sample Output
FJ can buy three packages from the second supplier for a total cost of 9.
题解
f[i]表示购买至少i的干草的花费,f[remin(v+p[i],h)]=min(f[remin(v+p[i],h)],f[v]+c[i]);
代码
/*Author:WNJXYK*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std; #define LL long long
#define Inf 2147483647
#define InfL 10000000000LL inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;} const int Maxn=50000;
const int N=100; int f[Maxn+10];
int p[N+10];
int c[N+10];
int n,h;
int main(){
scanf("%d%d",&n,&h);
for (int i=1;i<=n;i++) scanf("%d%d",&p[i],&c[i]);
memset(f,127,sizeof(f));
f[0]=0;
for (int i=1;i<=n;i++){
for (int v=0;v<=h;v++){
f[remin(v+p[i],h)]=remin(f[remin(v+p[i],h)],f[v]+c[i]);
}
}
printf("%d\n",f[h]);
return 0;
}
BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草的更多相关文章
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )
无限背包dp.. 因为题目中说至少到 H 磅 , 我就直接把 H * 2 了.. ----------------------------------------------------------- ...
- bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草【背包】
好像是完全背包吧分不清了-- 好像是把数组二维压一维的时候,01背包倒序,完全背包正序 ```cpp include include using namespace std; const int N= ...
- 【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1618 裸的01背包,注意背包的容量不是v即可. #include <cstdio> #i ...
- [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草
[BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草 试题描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草. 他知道N(1≤N≤100)个干草 ...
- [Usaco2008 Nov]Buying Hay 购买干草[背包]
Description 约翰的干草库存已经告罄,他打算为奶牛们采购日(1≤日≤50000)磅干草. 他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重 ...
- [Usaco2008 Nov]Buying Hay 购买干草
题目描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅 ...
- BZOJ 1229: [USACO2008 Nov]toy 玩具
BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...
- BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )
二分一下答案就好了... --------------------------------------------------------------------------------------- ...
- BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )
状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) = Σ dp( i , S - { i } ) ( i ∈ S , ...
随机推荐
- Open virtual effects in Ubuntu 12.04LTS
Need install below packages: compiz compiz-core compiz-fusion-plugins-extra+ compiz-fusion-plugins-m ...
- iOS设计模式——MVC(Model-View-Controller)
Modol View Controller(MVC)是一种最早的也是最成功的可重用的设计模式,70年代的时候首次在smaltalk编写的程序中成功使用.基于MVC设计 模式,Cocoa整体架构可以划分 ...
- python学习(序章)
好久没写过笔记了,最近听说写博客笔记能使知识记忆更深刻,于是就开始写写,不为推广,只为增加记忆.好了,开始python的学习: 学习一门语言的快慢,与人无关,主要是与学习的目的有关,python语言目 ...
- Ajax+asp.net实现用户登陆 转自http://www.shangxueba.com/jingyan/2933319.html
这篇文章主要介绍了Ajax+asp.net实现用户登陆,主要是为了练习ajax的使用方法,有需要的小伙伴参考下. 以用户登录为例练习ajax的使用方法 login.html <!DOCTYPE ...
- Windows NTService 后台框架封装
对于后台运行的程序,比如基于C/S架构的服务器.各种监控系统的程序.或者是程序额外的功能需要后台运行来实现,在Windows平台中,服务经常会用到,这种对于需要24×7运行的程序是必备的,至少本人经常 ...
- relative、absolute和float
relative.absolute和float position:relative和position:absolute都可以改变元素在文档中的位置,都能激活元素的left.top.right.bo ...
- R语言学习之主成分分析法的R实践
主成分分析R软件实现程序(一): >d=read.table("clipboard",header=T) #从剪贴板读取数据 >sd=scale(d) #对数据进行标 ...
- python自学笔记(四)python基本数据类型之元组、集合、字典
一.元组tuple 特性 1.有序集合 2.通过偏移来取数据 3.不可变对象,不能在原地修改内存,没有排序.修改等操作 元组不可变的好处:保证数据的安全,比如我们传给一个不熟悉的方法,确保不会改变我们 ...
- C——货物管理系统
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> ...
- 配置管理多个ssh key
假设需要为两台主机建立ssh key以便抓取.更新代码,主机A:111.111.111.111,主机B:222.222.222.222. 首先,用两个账户(hostA@email.com与hostB@ ...