无限背包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. nyist 500 一字棋

    题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=500 这太并不难,只要把情况分清楚就可以了,本人由于考虑不是很周全,WA了n次....悲 ...

  2. Intellij IDEA + Android SDK + Genymotion Emulator打造最佳Android开发

    原文:Intellij IDEA + Android SDK + Genymotion Emulator打造最佳Android开发 Intellij IDEA + Android SDK + Geny ...

  3. QVector 和vector的比较

    QVector和vector的比较: Qvector默认使用隐式共享,可以用setSharable改变其隐式共享.使用non-const操作和函数将引起深拷贝.at()比operator[](),快, ...

  4. 通过jstack定位在线执行java系统故障_案例1

    问题描写叙述: 在一个在线执行的java web系统中,会定时执行一个FTP上传的任务,结果有一天发现,文件正常生成后却没有上传. 问题初步分析: 1.查看日志文件 发现这个任务仅仅打印了開始进入FT ...

  5. jQuery 插件 flexslider 初步使用

    发现了个不错的 jQuery 幻灯片插件 flexslider,有 接近 3000 Star,应该说是很靠谱的,下面是简单使用教程. 引入代码 所有代码都可以在 flexlslider 的 Githu ...

  6. 视频媒体播放,最好的 HTML 解决方法

    最好的 HTML 解决方法 HTML 5 + <object> + <embed> <video width="320" height="2 ...

  7. Unity Editor下对资源进行操作时调用AssetModificationProcessor

    public class Test : UnityEditor.AssetModificationProcessor { private static void OnWillCreateAsset(s ...

  8. BZOJ 2982: combination( lucas )

    lucas裸题. C(m,n) = C(m/p,n/p)*C(m%p,n%p). ----------------------------------------------------------- ...

  9. Android 使用 intent 实现简单登陆页面

    前言 第一个 Android 程序,应该有些纪念的意义吧~ 主页面布局 给 Button 添加响应函数:android:onClick="login" public void lo ...

  10. A Byte of Python 笔记(10)输入/输出:文件和储存器

    第12章  输入/输出 大多数情况下,我们需要程序与用户交互.从用户得到输入,然后打印一些结果. 可以分别使用 raw_input 和 print 语句来完成这些功能.对于输出,可以使用多种多样的 s ...