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

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 1216  Solved: 633
[Submit][Status][Discuss]

## Description

N给它们编号。第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅,需要的开销为Ci(l≤Ci≤5000)美元．每个干草公

2 15
3 2
5 3

## Sample Output

9
FJ can buy three packages from the second supplier for a total cost of 9.

Silver

## Code

 1 #include<cstdio>
2 #include<iostream>
3 #define maxn 1000000
4 using namespace std;
5
6 int DP[maxn],n,h,w[maxn],v[maxn],inf = 0x3f3f3f3f;
7
8 int main(){
9     scanf("%d%d",&n,&h);
10
11     for(int i = 1;i <= n;i++){
12         scanf("%d%d",&v[i],&w[i]);
13     }
14
15     for(int i = 1;i <= h;i++){
16         DP[i] = inf;
17     }
18
19     for(int i = 1;i <= n;i++){
20         for(int j = 1;j <= h;j++){
21             if(v[i] >= j) DP[j] = min(DP[j],w[i]);
22             else DP[j] = min(DP[j],DP[j-v[i]]+w[i]);
23         }
24     }
25
26     printf("%d",DP[h]);
27
28     return 0;
29 }

posted @ 2017-09-02 22:38  Leviaton  阅读(120)  评论(0编辑  收藏  举报