zoukankan      html  css  js  c++  java
  • [BZOJ1618][Usaco2008 Nov]Buying Hay 购买干草

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

    Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1224  Solved: 639 [Submit][Status][Discuss]

    Description

    约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到
    N给它们编号。第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅,需要的开销为Ci(l≤Ci≤5000)美元.每个干草公
    司的货源都十分充足,可以卖出无限多的干草包.    帮助约翰找到最小的开销来满足需要,即采购到至少H磅干草

    Input

    第1行输入N和H,之后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.
     
    完全背包
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    char buf[10000000], *ptr = buf - 1;
    inline int readint(){
        int n = 0;
        char ch = *++ptr;
        while(ch < '0' || ch > '9') ch = *++ptr;
        while(ch <= '9' && ch >= '0'){
            n = (n << 1) + (n << 3) + ch - '0';
            ch = *++ptr;
        }
        return n;
    }
    int dp[50000 + 10];
    int main(){
        fread(buf, sizeof(char), sizeof(buf), stdin);
        memset(dp, 0x3f, sizeof dp);
        dp[0] = 0;
        int n, H;
        n = readint();
        H = readint();
        for(int p, c, i = 1; i <= n; i++){
            p = readint();
            c = readint();
            for(int i = 1; i <= p && i <= H; i++)
                dp[i] = min(dp[i], c);
            for(int i = p + 1; i <= H; i++)
                dp[i] = min(dp[i], dp[i - p] + c);
        }
        printf("%d
    ", dp[H]);
        return 0;
    }
  • 相关阅读:
    VI的常用命令【工具篇】
    linux中安装中文字体
    阅读源代码,学习PostgreSQL数据库 (1) 准备工作
    如何安装gcc 3.3.6
    Buffered I/O and nonbuffered I/O
    Linux下查看硬件配置的相关命令
    linux disk i/o shceduler
    Linux编译内核操作流程 ——为新手指南
    HDOJ 1026 Ignatius and the Princess I
    HDOJ 2544 最短路 SPFA算法
  • 原文地址:https://www.cnblogs.com/ruoruoruo/p/7486576.html
Copyright © 2011-2022 走看看