zoukankan      html  css  js  c++  java
  • 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

        约翰的干草库存已经告罄,他打算为奶牛们采购日(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.


    题解


    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
    ",f[h]);
    	return 0;
    }
    



  • 相关阅读:
    idea删除module
    使用腾讯云mysql的一下小坑
    docker 从 tomcat 容器连接到 mysql 容器
    数据结构开发(16):选择排序和插入排序
    数据结构开发(15):递归的思想与应用
    数据结构开发(14):KMP 子串查找算法
    数据结构开发(13):字符串类的创建
    数据结构开发(11):双向循环链表的实现
    数据结构开发(10):Linux内核链表
    数据结构开发(9):循环链表与双向链表
  • 原文地址:https://www.cnblogs.com/WNJXYK/p/4063917.html
Copyright © 2011-2022 走看看