Describe
http://www.lydsy.com/JudgeOnline/problem.php?id=1618
There are n kinds of goods, each item has value and weight, can be unlimited. Now to meet the value of the sum of greater than equals H, ask the minimum weight.
Analysis
Full backpack, the template is given the maximum value of the weight, the problem is given the value of the smallest weight. In fact, almost.
P.s. Maybe I can only do this water problem.
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intn= -+5, w=50000+5, inf=0x3fffffff;5 intn,h;6 intDp[w],w[n],v[n];7InlinevoidReadint&ret) {8ret=0;intk=1;CharC;9 for(C=getchar ();c<'0'|| C>'9'; C=getchar ())if(c=='-') k=-1;Ten for(; c>='0'&&c<='9'; C=getchar ()) ret=ret*Ten+c-'0'; Oneret*=K; A } - intMain () { - read (n); Read (h); the for(intI=1; i<=n;i++) read (V[i]), read (W[i]); - for(intI=1; i<=h;i++) dp[i]=INF; - for(intI=1; i<=n;i++) for(intj=1; j<=h;j++){ - if(V[I]>=J) dp[j]=min (dp[j],w[i]); + ElseDp[j]=min (dp[j],dp[j-v[i]]+w[i]); - } +printf"%d\n", Dp[h]); A return 0; at}
View Code
1618: [Usaco2008 nov]buying hay buy hay time limit:5 Sec Memory limit:64 MB
submit:950 solved:488
[Submit] [Status] [Discuss] DescriptionJohn's Hay inventory has been depleted, and he intends to buy the cows for the day (1≤ day ≤50000) pound of hay. He knew N (1≤n≤100) Hay Company, now numbering them with 1 to N. The first company sells hay bales with a weight of Pi (1≤pi≤5000) lbs, requiring a cost of Ci (l≤ci≤5000) USD. Every hay company has enough supplies to sell an unlimited number of hay bales. Help John find the minimum cost to meet the needs, i.e. procure to at least h pound hay. Inputline 1th enters N and th, and then each row of n lines enters a pi and CI. Outputthe minimum overhead. Sample Input2 15
3 2
5 3
Sample Output9
FJ can buy three packages from the second supplier for a total cost of 9.
Hintsource
Silver
bzoj_1618_ [Usaco2008_nov]_buying_hay_ buy hay (Dynamic planning, full backpack)