EularProject 31: 2英镑的组合

来源:互联网 发布:免费手机数据恢复精灵 编辑:程序博客网 时间:2024/05/01 20:25

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:
73682Completed on Tue, 3 Feb 2015, 13:16

Go to the thread for problem 31 in the forum.

Download overview for problem 31.


见到这个题目我的第一感觉就是要用我的第一篇博文关于整数划分的一篇介绍:整数划分

 另一种思路就是使用完全背包问题求解的方法

#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

邮箱: 1194603539@qq.com


0 0
原创粉丝点击