题目链接: 点击打开链接
题目大意: 给定一个面额,求将这个面额换算成硬币的方案数。硬币有美元美分两种,面额不超过$300.00。
思路: 动态规划,完全背包
分析:
和uva 647思路一样,不过需要换算一下,注意答案会超出int范围,得用long long存。
代码:
#include <cstdio>
#include <memory.h>
using namespace std;
const int maxc = 30000 + 10;
int coins[11] = {5, 10, 20, 50, 100, 200, 500,
1000, 2000, 5000, 10000};
int cents;
long long dp[maxc];
int change(double input)
{
return (input + 0.005) * 100;
}
void solve()
{
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < 11; ++i)
for (int j = coins[i]; j <= cents; ++j)
dp[j] += dp[j - coins[i]];
}
int main()
{
double input;
while (scanf("%lf", &input) && change(input) != 0)
{
cents = change(input);
solve();
printf("%6.2lf%17lld\n", input, dp[cents]);
}
}