码迷,mamicode.com
首页 > 编程语言 > 详细

(HW)Permutation(Java)

时间:2019-05-31 23:12:16      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:ext   span   get   add   new   str   java   system   key   

 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)

标签:ext   span   get   add   new   str   java   system   key   

原文地址:https://www.cnblogs.com/Huayra/p/10957704.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!