Project Euler:Problem 31 Coin sums
来源:互联网 发布:淘宝店铺号可以改吗 编辑:程序博客网 时间:2024/06/11 20:09
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?
#include <iostream>#include <vector>using namespace std;int compute(int f, vector<int> a){if (a.size() == 0 || f < 0)return 0;if (f == 0 || a.size() == 1)return 1;else{int largest;largest = a[a.size() - 1];int uses = f / largest;int count = 0;if (a.size() >= 1)a.pop_back();for (int i = 0; i <= uses; i++)count += compute(f - largest*i, a);return count;}}int main(){int f = 200;int a[8] = { 1, 2, 5, 10, 20, 50, 100, 200 };vector<int>coins(a, a + 8);cout << compute(f, coins) << endl;system("pause");return 0;}
0 0
- Project Euler:Problem 31 Coin sums
- Project Euler 31- Coin sums
- Coin sums Problem 31
- Project Euler:Problem 23 Non-abundant sums
- Project Euler:Problem 78 Coin partitions
- Project Euler Problem 31
- Project Euler - Problem 31
- Project Euler problem 31
- Project euler problem 31 - 40
- Project Euler 78 : Coin partitions
- Problem 31 Coin sums(完全背包dp)
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- Project Euler Problem 57
- [置顶]iOS_Spring自动生成Model,Service,Controller 之 使用教程
- OracleLinux-R7-U1-Server-x86_64下安装oracle-11.2.0.4.0_linux_x86和x86_64
- 用户输入校对函数
- 关于android旋转屏幕时activity重建和android 转屏 onConfigurationChanged 不会执行的问题
- keyup() 方法
- Project Euler:Problem 31 Coin sums
- multiple file upload 多文件上传精典
- httpclient简单例子,一种简单的webservice
- no link present
- C—learning (字符,转义字符,浮点型,printf函数,
- 纪念成为CSDN博客专家
- VisualStudio 路径和项目属性配置
- UML视图
- 批处理学习笔记1:文件搜索