(HW)Permutation(Java)
发布日期:2021-09-05 00:32:48 浏览次数:9 分类:技术文章

本文共 1072 字,大约阅读时间需要 3 分钟。

1 public class test 2 { 3     public static void main(String[] args) 4     { 5         Vector
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
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 }

 

转载于:https://www.cnblogs.com/Huayra/p/10957704.html

转载地址:https://blog.csdn.net/weixin_34228387/article/details/93199703 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:To want to inspire motive, we must first MBT Kisumu
下一篇:外观模式(Facade Pattern)

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月12日 18时14分53秒