zoukankan      html  css  js  c++  java
  • BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )

    无限背包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 << " ";
    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

  • 相关阅读:
    Scala 获取当前时间
    mnist 数据集的识别源码解析
    tf.nn.softmax_cross_entropy_with_logits的用法
    softmax函数
    实现手写体 mnist 数据集的识别任务
    MNIST 数据集
    神经网络之激活函数
    模块化神经网络
    np.c_与np.r_
    学习率的选取-滑动平均
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4556939.html
Copyright © 2011-2022 走看看