1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 105 #define M 55005 #define INF 0x3f3f3f3f using namespace std; int dp[M],p[N],c[N]; int main(){ int n,h; cin >> n >> h; for (int i = 1;i<=n;i++) cin >> p[i] >> c[i]; memset(dp,0x3f,sizeof dp); dp[0] = 0; for (int i = 1;i<=n;i++){ for (int j = p[i];j<=h + 5000;j++){ //题目要求至少买h,所以多买点没关系 dp[j] = min(dp[j - p[i] ] + c[i],dp[j] ); } } int ans = INT_MAX; for (int i = h;i<=h+5000;i++) ans = min(ans,dp[i]); cout << ans; return 0; }
- 1
Information
- ID
- 113
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 1
- Accepted
- 1
- Uploaded By