Atcoder Beginner Contest153E (full backpack)

Full backpack, take the meaning of the questions the value of the minimum price

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int a[10007],b[10007],f[10007];
 5 int main(){
 6     ios::sync_with_stdio(false);
 7     cin.tie(NULL);
 8     cout.tie(NULL);
 9     int h,n;
10     cin>>h>>n;
11     for(int i=1;i<=n;++i)
12         cin>>a[i]>>b[i];
13     for(int i=1;i<=h;++i)
14         f[i]=1e9;
15     f[0]=0;
16     for(int i=1;i<=n;++i)
17         for(int j=0;j<=h;++j){
18             int x=max(0,j-a[i]);
19             f[j]=min(f[j],f[x]+b[i]);
20         }
21     cout<<f[h];
22     return 0;
23 }

 

Guess you like

Origin www.cnblogs.com/ldudxy/p/12236134.html