BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
2017-10-18 21:52
453 查看
1618: [Usaco2008 Nov]Buying Hay 购买干草
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1309 Solved: 678
[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 153 2
5 3
Sample Output
9FJ can buy three packages from the second supplier for a total cost of 9.
HINT
Source
Silver题解:
虽然很不想承认但我第一发居然WA了【其实wa了2发,第二发是数组开小了。。
注意干草包不一定恰好买h,可能超过。
#include<bits/stdc++.h> using namespace std; const int N = 100 + 5; const int M = 55000 + 5; int n,h; int p ,c ; int dp[M]; int main(){ scanf("%d%d",&n,&h); for(int i=1;i<=n;++i) scanf("%d%d",&p[i],&c[i]); memset(dp,63,sizeof(dp)); dp[0]=0; for(int i=1;i<=n;++i){ for(int j=p[i];j<=h+5000;++j){ dp[j]=min(dp[j],dp[j-p[i]]+c[i]); } } int ans=1000000000; for(int i=h;i<=h+5000;++i) ans=min(ans,dp[i]); printf("%d",ans); return 0; }
顺便bzoj 大号第100题(其实是102但有2道不是我做的)居然是这道傻逼题。。。
相关文章推荐
- bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草(完全背包)
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草( dp )
- 背包DP-BZOJ-1618-[Usaco2008 Nov]Buying Hay 购买干草
- bzoj1618【Usaco2008 Nov】Buying Hay 购买干草
- 【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)
- 【BZOJ 1618】 [Usaco2008 Nov]Buying Hay 购买干草
- 【bzoj1618】【Usaco2008 Nov]】Buying Hay 购买干草
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
- [BZOJ] 1618: [Usaco2008 Nov]Buying Hay 购买干草
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
- bzoj1618[Usaco2008 Nov]Buying Hay 购买干草
- bzoj 1618: [Usaco2008 Nov]Buying Hay 购买干草【背包】
- bzoj1618[Usaco2008 Nov]Buying Hay 购买干草
- [BZOJ1618] [Usaco2008 Nov]Buying Hay 购买干草
- BZOJ_1618_ [Usaco2008_Nov]_Buying_Hay_购买干草(动态规划,完全背包)
- 1618: [Usaco2008 Nov]Buying Hay 购买干草
- BZOJ 1618: [Usaco2008 Nov]Buying Hay 购买干草
- [Usaco2008 Nov]Buying Hay 购买干草[背包]
- BZOJ1618: [Usaco2008 Nov]Buying Hay 购买干草
- bzoj1618: [Usaco2008 Nov]Buying Hay 购买干草 完全背包