风言枫语  

解法同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\n",d,nWay[Money]);
	}
	return 0;
}


 

 

posted on 2013-08-26 19:33  风言枫语  阅读(166)  评论(0编辑  收藏  举报