(HW)CoinsCombination(Java)
Posted huayra
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(HW)CoinsCombination(Java)相关的知识,希望对你有一定的参考价值。
1 public class test 2 3 public static void main(String[] args) 4 5 Vector<Integer> v = new Vector<>(); 6 v.add(1); 7 v.add(2); 8 v.add(5); 9 Vector<Integer> solution = new Vector<>(); 10 Scanner input = new Scanner(System.in); 11 int dst = input.nextInt(); 12 System.out.println(CoinsCombination(v, solution, 0, 0, dst)); 13 input.close(); 14 15 16 public static int CoinsCombination(Vector<Integer> v, Vector<Integer> solution, int start, int sum, int dst) 17 18 if(dst <= 0) 19 return 0; 20 if(sum == dst) 21 22 System.out.println(solution.toString()); 23 return 1; 24 25 if(sum > dst) 26 return 0; 27 28 int count = 0; 29 for(int i = start; i < v.size(); i++) 30 31 solution.add(v.get(i)); 32 sum += v.get(i); 33 count += CoinsCombination(v, solution, i, sum, dst); 34 solution.remove(solution.size() - 1); 35 sum -= v.get(i); 36 37 38 return count; 39 40
以上是关于(HW)CoinsCombination(Java)的主要内容,如果未能解决你的问题,请参考以下文章