但每个组合中都有每个元素

但每个组合中都有每个元素

本文介绍了从数组生成唯一的组合,但每个组合中都有每个元素。 (java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数组中生成所有可能的唯一组合,但是它不如生成所有组合那样简单……。我有一个数组{a,b,c,d,e,f} ...我的结果应该是这样的...

I am trying to generate every possible unique combination from an array, but its not as straightforward as generating all combinations..... Eg. I have an array {a,b,c,d,e,f} ... my result should be like this...


  1. ab,cd,ef

  2. abc,def

  3. ac,bd,ef

  4. abcf,ed

  5. .... etc

  1. ab, cd, ef
  2. abc, def
  3. ac, bd, ef
  4. abcf, ed
  5. ....etc

......基本上在每个结果集中数组的所有元素都应包括在内。... ab与 ba相同, abcd与 dcba或 cbda相同....位置无所谓... 。并且不允许重复...'aaa'或'aa'无效...如果有人可以提供解决此问题的方法,将不胜感激...。

...... basically in every result set all elements of the array should be included .... Also 'ab' is the same as'ba' and 'abcd' is the same as 'dcba' or 'cbda' .... The position does not matter .... and no repetition allowed ... 'aaa' or 'aa' is not valid ... would be grateful if someone could provide a solution for this problem ....

推荐答案

 String [] new_array=new String[N];
 array.length=length.of("befdac");
 for(int i=0;i < array.length;i++) //this is first digit

{

for(int j=0;j < array.length;j++) //this is second digit
{
if(i==j)continue;
       ................ same with other digits

        {
         if((i==j)||(i==k)) continue;
        // start counting in this most inner block
        new_array[i][j][k][l]...[last_digit]=byte(i+65)+byte(j+65)+byte(k+65)+.....+byte(last_digit+65);
        //65=a, 66=b,......

         }
 }
}

new_array [] [] [] [] ... []将是您没有尝试过的代码。你最好自己做。这不是最优化的。只是为了第一个答案而获得一些分数

new_array[][][][]...[] will be your code i didnt tried . best thing u do it yourself. this is not optimized. just made for first answer to get some points

这篇关于从数组生成唯一的组合,但每个组合中都有每个元素。 (java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:55