无限背包dp..

因为题目中说至少到 H 磅 , 我就直接把 H * 2 了..

--------------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = int( 1e5 ) + 5;
const int inf = 0x3f3f3f3f;
 
int d[ maxn ];
 
int main() {
// freopen( "test.in" , "r" , stdin );
int n , h;
cin >> n >> h;
h *= 2;
clr( d , inf );
d[ 0 ] = 0;
rep( i , n ) {
int w , v;
scanf( "%d%d" , &w , &v );
for( int i = w ; i <= h ; i++ )
   d[ i ] = min( d[ i ] , d[ i - w ] + v );
   
}
int ans = inf;
for( int i = h / 2 ; i <= h ; i++ )
   ans = min( ans , d[ i ] );
   
cout << ans << "\n";
return 0;
}

--------------------------------------------------------------------------

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 749  Solved: 379
[Submit][Status][Discuss]

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

BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. [Usaco2008 Nov]Buying Hay 购买干草

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

  7. BZOJ 1231: [Usaco2008 Nov]mixup2 混乱的奶牛( dp )

    状压dp dp( x , S ) 表示最后一个是 x , 当前选的奶牛集合为 S , 则状态转移方程 : dp( x , S ) =  Σ dp( i , S - { i } )  ( i ∈ S , ...

  8. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  9. BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )

    -------------------------------------------------------------------- #include<cstdio> #include ...

随机推荐

  1. javascript简单对象创建

    由于javascript中定义了一个函数就相当于定义了一个类,我们当然可以创建一个这个类的对象. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 ...

  2. linux下解压iso文件

    .iso文件的格式是iso9660,iso9660是cd上的一种文件系统, 也就是说是 是数据在cd上的组织形式: 它的一些限制是: 1.最多8级子目录(可以用RockRidge Extension增 ...

  3. linux下mysql出现Access denied for user 'root'@'localhost' (using password: YES)解决方法

    # /etc/init.d/mysql stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # my ...

  4. openStack openSource CloudComputing

    <一,> ,OpenStack a few Core Compontents integration with openStack-keystone Identity service1.1 ...

  5. 对JAVA Bean使用PropertyDescriptor反射调用JAVA方法

    对于符合JAVA Bean规范的bean,调用其方法应优先使用java.beans.PropertyDescriptor获取Method进行方法调用,以获得更大的可维护性. 示比例如以下: NonCo ...

  6. 关于js封装框架类库之样式操作

    在js中,对样式的操作我们并不感到陌生,在很多框架中都是用极少的代码,实现更强大的功能,在这做出一些的总结.存在不足还望指出! 1.封装一个添加css的方法(这篇引用了前面的框架结构) 在 js 中 ...

  7. Hibernate与iBATIS的比较

    1.出身 hibernate 是当前最流行的o/r mapping框架,它出身于sf.net,现在已经成为jboss的一部分了. ibatis 是另外一种优秀的o/r mapping框架,目前属于ap ...

  8. mysql 时间差问题集锦

    SELECT * from grouptoadd where taskid = '103244'; select datediff(max(spreadtime),min(createtime)) f ...

  9. 关于$.ajax的请求格式

    1 $.ajax({ 2 url: "http://localhost:5311/UserService.asmx/GetLoginId",//请求的URL 3 type: &qu ...

  10. Object-c Block的使用及说明

    Object-c 中的block就好像一段C函数般,由函数名,有返回值,有参数,由函数体等 1.简单的block ^(int A ,int B) { int C=A*B; return C; }; 上 ...