也是不会做然后去看了题解,有个方法很巧妙,也算是完全背包的变形吧
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int extra = 5000;
const int maxn = 1e9;
int dp[60000];
int main()
{
int n, h, w, p;
cin >> n >> h;
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i < n; i++)
{
cin >> w >> p;
/*以下分类完美解决了“至少”问题*/
for (int j = 1; j <= w; j++)
{
dp[j] = min(dp[j], p);
}
for (int j = w; j <= h; j++)
{
dp[j] = min(dp[j], dp[j - w] + p);
}
}
cout << dp[h] << endl;
return 0;
}