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

 

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

题意:

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

 

思路:

很明显的完全背包。

 1 #include<iostream> 
 2 #include<string>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 const int INF = 100000;
 8 
 9 int d[10005];
10 int a[3] = { 150, 200, 350 };
11 
12 int main()
13 {
14     //freopen("D:\\txt.txt", "r", stdin);
15     int T, s;
16     cin >> T;
17     while (T--)
18     {
19         cin >> s;
20         memset(d, 0, sizeof(d));
21         for (int i = 150; i <= s;i++)
22         for (int j = 0; j < 3 && a[j] <= i; j++)
23             d[i] = max(d[i], d[i - a[j]] + a[j]);
24         cout << s-d[s] << endl;
25     }
26     return 0;
27 }

 

posted @ 2017-02-08 22:12  Kayden_Cheung  阅读(154)  评论(0编辑  收藏  举报
//目录