生成受理的排列 [英] Generate admissible permutations

查看:133
本文介绍了生成受理的排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成的一组列出所有可能的排列,但排列是不是所有的资格。该排列是作为集列表的子集的排列组合。

I would like to generate all possible permutations of a set List but the permutations are not all eligible. The permutations are as combinations of subsets' permutations of the set List.

例如,我们有由两个子集的以下列表:列表= {(1,2),(3,4)}; 受理的排列是:1234/1243/2134/2143/3412/4312/3421/4321 下面的排列则不予受理:1423/3142/1324/1342/2431/2341 / ...

For example we have the following list composed of two subsets: List = {(1,2), (3,4)}; admissible permutations are : 1234/1243/2134/2143/3412/4312/3421/4321 the following permutations are not admissible: 1423/3142/1324/1342/2431/2341 / ....

我已经生成的所有可能的排列而不是那些受理。

I have generated all possible permutations but not those admissible.

static void permute(ArrayList<Integer> arr, int k){
  for(int i = k; i < arr.size(); i++){
      java.util.Collections.swap(arr, i, k);
      permute(arr, k+1);
      java.util.Collections.swap(arr, k, i);
  }
  if (k == arr.size() -1){
      System.out.println(java.util.Arrays.toString(arr.toArray()));
  }

}

我真的很需要这个code计算欧文(博弈论)的值。谢谢你在前进

I'm really need this code to calculate the value of Owen (game theory). Thank you in advance

推荐答案

这里的问题是,你所得到的第一个数组,然后第二阵列和可能的排列串联它们,你需要做的是做同样的事你在code那样,然后做一个新2darray具有第一阵列的第一值,和第二阵列的第一值,所述第二阵列的则第二个值,第一个,然后第二值数组。让你找到的排列可能与{(1,2),(3,4)}使用当前的技术,然后你发现的排列可能与{(1,3),(2,4)}和{(1, 4),(2,4)}等。

the issue here is that you are getting the possible permutations of the first array, then the second array and concatenating them, what you need to do is do the same thing you did in your code, then make a new 2darray that has the first value of the first array, and the first value of the second array, then the second value of the second array, then the second value of the first array. so you find the permutations possible with {(1,2), (3,4)} using your current technique, then you find the permutations possible with {(1,3), (2,4)} and {(1,4), (2,4)} and so on.

如果您有更多然后2列表,然后一个有用的来源是的 http://www.programcreek.com/2013/02/leet$c$c-permutations-java/ 它解释的过程中,有code,说明。

If you have more then 2 lists then a helpful source is http://www.programcreek.com/2013/02/leetcode-permutations-java/ it explains the process, and has code that illustrates.

这篇关于生成受理的排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆