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