题意:
换硬币
思路:
跟之前做的uva674 - Coin Changehttp://blog.csdn.net/conatic/article/details/50850516 是同款题,但这题有几个要注意的地方就是:
1.long long 问题,可能性有可能非常大
2.精度问题,惨死在这里T_T(见代码部分),还是看了人家题解才知道错在这里。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[11] = {5, 10, 20, 50, 100,200,500, 1000, 2000, 5000, 10000 };
long long dp[30005][11];
int n;
long long DP(int i,int j) {
if (j == 0)
return dp[i][j] = 1;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 0;
for (int k = 0; i - k*a[j] >= 0; k++){
dp[i][j] += DP(i - k*a[j], j - 1);
}
return dp[i][j];
}
int main() {
double t;
memset(dp, -1, sizeof(dp));
while (~scanf("%lf", &t) && (t - 1e-9 > 0)) {
n = (int)(t * 100+0.5);//漏了+0.5,WA了好几发
printf("%6.2f%17lld\n", t, DP(n,10));
}
}