HDU 1248 寒冰王座(完全背包)

时间:2022-01-26 15:59:06

http://acm.hdu.edu.cn/showproblem.php?pid=1248

题意:

商店里只有三种物品,价格分别为150,200,350。输入钱并计算浪费的钱的最小值,商店不找零。

思路:

很明显的完全背包。

 #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std; const int INF = ; int d[];
int a[] = { , , }; int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int T, s;
cin >> T;
while (T--)
{
cin >> s;
memset(d, , sizeof(d));
for (int i = ; i <= s;i++)
for (int j = ; j < && a[j] <= i; j++)
d[i] = max(d[i], d[i - a[j]] + a[j]);
cout << s-d[s] << endl;
}
return ;
}