题目大意:给出11种硬币的价值,非别为100,50,20,10,5,2,1,0.5,0.2,0.1,0.05
现在给出一个数,问这个数有多少种组成方式
解题思路:有小数的话,比较麻烦,所以先转成整数,然后就是完全背包问题了
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 30010;
long long dp[N];
int val[12] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
int main() {
double t;
while (scanf("%lf", &t) != EOF) {
int m = (int)(round(t * 100.0));
if (!m) break;
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < 11; i++)
for (int j = val[i]; j <= m; j++)
dp[j] += dp[j - val[i]];
printf("%6.2lf%17lld\n", t, dp[m]);
}
return 0;
}