UVa 147 - Dollars

传送门

UVa 147 - Dollars

思路

和前面换硬币那题一样,不过浮点数要换成整数,用long long 保存。

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN = 30000 + 100;
const int mon[] = {10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5};

LL d[MAXN][12];

LL DP(int rim, int us)
{
    LL &ans = d[rim][us];
    if (ans != -1)
        return ans;
    ans = 0;
    for (int i = us; i < 11; i++)
        if (rim >= mon[i])
            ans += DP(rim - mon[i], i);
    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    double temp;
    LL i, j, ans, money;
    memset(d, -1, sizeof(d));
    for (i = 0; i < 11; i++)
        d[0][i] = 1;
    while (scanf("%lf", &temp), temp)
    {
        money = (int)((temp + 0.005) * 1e2);
        ans = DP(money, 0);
        printf("%6.2f%17lld\n", temp, ans);
    }
    return 0;
}

Powered by Jekyll and Theme by solid