欧拉计划——31
来源:互联网 发布:重庆 深圳 知乎 编辑:程序博客网 时间:2024/06/03 12:36
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?
在英国,货币是由英镑£,便士p构成的。一共有八种钱币在流通:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) 和 £2 (200p).
要构造£2可以用如下方法:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
允许使用任意数目的钱币,一共有多少种构造£2的方法?
package com.fk.euler;/** * Created by fengkai on 1/14/17. */public class Euler31 {public static void main(String[] args) { int[] coin = {200,100, 50, 20, 10, 5, 2, 1}; int target = 200; System.out.println(getCoint(coin, target, coin[0]));}private static int getCoint(int[] coin, int target, int c) { if (c == 1) { return 1; } if (target == 0) { return 1; } int max = target / c; int sum = 0; for (int i = 0; i <= max; i++) { int nextc = 1; for (int j = 0; j < coin.length; j++) { if (c == coin[j] && c != 1) { nextc = coin[j + 1]; break; } } sum += getCoint(coin, target - i * c, nextc); } return sum;}
}
思路有多种,具体吧官网文档放上吧,我写的是第一个种。
0 0
- 欧拉计划——31
- 欧拉计划 31
- 欧拉计划 100
- 欧拉计划
- 欧拉计划
- 欧拉计划是什么?
- 欧拉计划
- 欧拉计划3
- 欧拉计划
- 欧拉计划23
- 欧拉计划20
- 欧拉计划21
- 欧拉计划22
- 欧拉计划
- 欧拉计划 1
- 欧拉计划 2
- 欧拉计划 3
- 欧拉计划 4
- HDU 2012 素数打表
- 使用springMVC返回json数据是出现hibernateLazyInitializer
- 回文数的判断(考虑所有情况)
- Chrome浏览器——抢票插件的制作与插件工具(下)
- 理解HTTP和HTTPS的区别
- 欧拉计划——31
- 《Java 编程思想》-第2章 一切都是对象 笔记
- tensorflow及GPU加速在win10下的安装教程
- Android的材料设计兼容库(Design Support Library)
- JBPM工作流入门总结
- OpenCV计时代码段
- 关于lambda引出的碎碎念
- 红黑树
- 我的标题233