题目链接:https://nanti.jisuanke.com/t/41401
给你n种饮料,和一个m,n种饮料无限供应,给出每种饮料的价格和容量,要求求至少体积为m的饮料的最小价格和
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
struct node
{
int cost;
int weight;
} p[1010];
int dp[10010];
int m, n;
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
int i, j, jg = m, fg = inf;
memset(dp, inf, sizeof(dp));
// cout<<inf<<endl;
dp[0] = 0;
for (int i = 1; i <= n; i++)
scanf("%d%d", &p[i].cost, &p[i].weight);
for (i = 1; i <= n; i++) {
for (j = p[i].weight; j <= 10000; j++) {
dp[j] = min(dp[j], dp[j - p[i].weight] + p[i].cost);
if (j >= m) {
if (dp[j] == fg && j > jg)
jg = j;
else if (dp[j] < fg) {
fg = dp[j];
jg = j;
}
}
}
}
cout << fg << ' ' << jg << endl;
}
return 0;
}