问题描述:
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 + 150p + 220p + 15p + 12p + 31p
How many different ways can £2 be made using any number of coins?
解决问题:
可以使用若干个for循环计算
for(int i=0;i<=2;i++){ //100
for(int j=0;j<=4;j++){ //50
for(int k=0;k<=10;k++){ //20
for(int l=0;l<=20;l++){ //10
for(int m=0;m<=40;m++){ //5
for(int n=0;n<=100;n++){ //2
int t = 200 - i*100 - j*50 - k*20 - l*10 - m*5 - n*2;
if(t>=0 ){
++index;
}
}
}
}
}
}
}
最好使用动态规划递归来计算,然后再使用非递归形式。
private static int[] coinValue = { 200, 100, 50, 20, 10, 5, 2 };
public static int count = 0;
public static void total(int level, int remain){
if(remain>=0){
count++;
}else{
return ;
}
int i=level ;
for(; i<7; i++){
total(i, remain - coinValue[i]);
}
}
分享到:
相关推荐
21.11 Command restrict problem 31 22. IOG related problem 31 22.1 Common part 31 22.2 NODE BLOCKED 33 22.3 STS Related Problems 33 22.4 Hanging System Backup 34 22.5 Charging Data Problem 35 22.6 ...
Computer Networking: A Top-Down Approach, 6th Edition Solutions to Review Questions and Problems Version Date: May 2012 ...This document contains the solutions to review questions ...Problem 1 There...
Use the inequality from [Pattern Classification, Chapter 2, Problem 31] to show that Pe approaches zero as the dimension d approaches infinity. (c) Express the meaning of this result in words. ...
Toth, P. and Vigo, D., 1997. An exact algorithm for the vehicle routing problem with backhauls. Transportation Science, 31, 372-3852.
在这个"0-1-knapsack-problem-master (31).zip"文件中,我们可以期待找到一个C语言实现的0-1背包问题解决方案。0-1背包问题的基本设定是:有n个物品,每个物品有重量wi和价值vi,还有一个背包,其最大承重为W。目标...
据说着名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39...然而Josephus 和他的朋友并不想遵从,Josephus要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。
Algorithmic Problem Solving with Python: John B. Schneider Shira Lynn Broschat Jess Dahmen: May 31, 2015
课堂测试31
该项目是一款基于Go语言的Container Problem Detect System异常检测器,源码包含2261个文件,涵盖1823个Go源文件、98个Markdown文件、51个Shell脚本文件、43个Git忽略文件、31个YAML配置文件、18个模板文件、14个...
文章目录CentOS 8.0 安装docker 报错:Problem: package docker-ce-3:19.03.4-3.el7.x86_64 requires containerd.io >= 1.2.2-31、错误内容2、分析原因3、解决4、检查是否安装成功 CentOS 8.0 安装docker 报错:...
### Ulam's Problem:在没有反馈的情况下搜索与说谎者博弈 #### 一、问题背景与定义 Ulam的问题起源于斯坦尼斯拉夫·乌拉姆(Stanislaw Ulam)提出的一个智力游戏,该问题涉及到如何在面对可能的谎言回答时确定一...
【标题】"31个城市坐标数据"涉及到的主要知识点是旅行商问题(Traveling Salesman Problem,简称TSP)以及相关的编程技术。旅行商问题是一个经典的组合优化问题,它描述了一个旅行商如何在访问n个城市一次并返回原点...
31城市旅行商问题(Traveling Salesman Problem, TSP)是一个著名的组合优化问题,其目标是找到一条访问每个城市一次并返回起点的最短路径。这个问题在实际应用中广泛出现,例如物流配送、电路布线等场景。 禁忌...
Delphi VCLSkin 5.30 ... VCLSkin is a component to create skinnable user interface for Delphi/C++Builder application, It is easy to use, just put one component on mainform, ...* fix caption paint problem...
【蚁群算法】是一种模拟生物界蚂蚁寻找食物过程的优化算法,主要应用于解决组合优化问题,如图中的旅行商问题(Traveling Salesman Problem,简称TSP)。在TSP问题中,一个销售员需要访问n个城市,每个城市仅访问一...
radiobutton,checkbox.News in 3.35 2005.9.5*Support TGroupbox font color.News in 3.34 2005.8.31*Fix paint problem in Trackbar when skin file change.News in 3.33 2005.8.29*Fix problem in TcxDBCheckbox....
【禁忌搜索解31城市TSP问题】是一个利用禁忌搜索算法解决旅行商问题(Traveling Salesman Problem,简称TSP)的案例。旅行商问题是一个经典的组合优化问题,旨在找到访问给定城市列表中每个城市一次并返回起点的最短...
31; 41; 41; 58; 59i. Such an input sequence is called an instance of the sorting problem. In general, an instance of a problem consists of the input (satisfying whatever constraints are imposed in ...
旅行商问题(Traveling Salesman Problem,简称TSP)是一个经典的组合优化问题,它源于实际生活中的配送、物流规划等场景。在31城市TSP问题中,一个旅行商需要访问31个城市,并且每个城市只访问一次,最后返回起点,...
标题中的"ACAbag.zip_31省会tsp_tsp"表明这是一个关于解决旅行商问题(Traveling Salesman Problem, TSP)的压缩文件,其中可能包含了算法实现或相关数据。旅行商问题是一个经典的组合优化问题,属于图论的一部分,...