bzoj1618: [Usaco2008 nov]buying hay buy hay full backpack

Source: Internet
Author: User

title : http://www.lydsy.com/JudgeOnline/problem.php?id=1618
1618: [Usaco2008 nov]buying Hay buys Hay
Time Limit:5 Sec Memory limit:64 MB
submit:939 solved:481
[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.

Ideas :
Bare full backpack;

Code :

#include <iostream>#include <stdio.h>#include <string.h>using namespace STD;intN,m;intdp[55005];intv[5005],w[5005];intMain () {scanf("%d%d", &n,&m); for(intI=1; i<=n;i++) {scanf("%d%d", &w[i],&v[i]); } for(intj=1; j<=m+ the; j + +) dp[j]=99999999; dp[0]=0; for(intI=1; i<=n;i++) for(intj=w[i];j<=m+ the; j + +) {dp[j]=min (dp[j],dp[j-w[i]]+v[i]); }intans=99999999; for(inti=m;i<=m+ the; i++) Ans=min (Ans,dp[i]);printf("%d\n", ans);}

bzoj1618: [Usaco2008 nov]buying hay to buy hay full backpack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.