UVa 147: Dollars

解法同UVa 674。只不过改用了滚动数组。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
#define max(i,j) (i>j?i:j)
#define maxn 6005
const int value[11] = { 1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000 };
long long nWay[maxn];

void dp(int m)
{
	for(int j=0; j<=m; j++) nWay[j] = 1;
	for(int i=1; i<11; i++)
		for(int j=1; j<=m; j++) if(j>=value[i])
			nWay[j] += nWay[j-value[i]];
}
int main()
{
	int a,b;
	double d;
	int Money;
	while(scanf("%d.%d",&a,&b)==2)
	{
		Money = (a*100+b)/5;
		d = a+b/100.0;
		if(d==0.00) break;
		dp(Money);
		printf("%6.2lf%17lld
",d,nWay[Money]);
	}
	return 0;
}


原文地址:https://www.cnblogs.com/keanuyaoo/p/3283395.html