您的位置:首页 > 其它

UVa 674 Coin Change(完全背包)

2017-02-08 22:23 399 查看
https://vjudge.net/problem/UVA-674

题意:

计算兑换零钱的方法共有几种。

思路:

完全背包基础题。

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int d[7500];
int a[5] = { 1, 5, 10, 25, 50 };

int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int s;
while (cin >> s)
{
memset(d, 0, sizeof(d));
d[0] = 1;
for (int i = 0; i < 5; i++)
{
for (int j = a[i]; j <= s; j++)
d[j] += d[j - a[i]];
}
cout << d[s] << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: