EularProject 31: 2英镑的组合

Coin sums

Problem 31

In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

It is possible to make £2 in the following way:

1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p

How many different ways can £2 be made using any number of coins?


Answer:
73682
Completed on Tue, 3 Feb 2015, 13:16

Go to the thread for problem 31 in the forum.

Download overview for problem 31.


见到这个题目我的第一感觉就是要用我的第一篇博文关于整数划分的一篇介绍:http://blog.csdn.net/zhangzhengyi03539/article/details/47102345

 另一种思路就是使用类似于斐波那契数列求解的方法

#include <iostream>
using namespace std;

const int maxn = 200;
int coin[8] = { 1, 2, 5, 10, 20, 50, 100, 200 };
int dp[maxn+1];
int m;

int main()
{
	int i, j;
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	for (i = 0; i<8; i++)
	{
		for (j = coin[i]; j <= maxn; j++)
		{
			if (j >= coin[i])
				dp[j] += dp[j - coin[i]];
		}
	}
	printf("%d\n", dp[maxn]);
	return 0;
}


------------------
祝身体健康,万事如意

华电北风吹

天津大学计算机科学与技术学院

天津市卫津路92号

邮编: 300072

邮箱: [email protected]


你可能感兴趣的:(EularProject 31: 2英镑的组合)