数组成员的Java数组的组合(骰子滚?) [英] combinations of an array of array members java ( dice roll? )

查看:243
本文介绍了数组成员的Java数组的组合(骰子滚?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不写在这里我在,因为我不知道如何开始,并没有运气搜索真的很抱歉。

really sorry for not writing where i am at, as i have no clue how to start and had no luck searching.

例如,如果我有

int [][]={{1,2,3},              //possible states of 1 member
          {10,20,30},           //possible states of 2 member
          {100,200,300}}        //possible states of 3 member

我需要定义的K - 组合件阵列的数量,然后在得到的方式的结果,我得到它们的状态的所有可能的组合。所以基本上,如果k是2:

I need to define k - number of combination member arrays, and then get the result in the way, that i get all possible combinations of their states. So basically if the k is 2:

member(1st array)1 - member2
member1 - member3 
member2 - member3

然后得到的那些成员的所有可能状态的组合,该部件不能彼此结合

Then get combinations of all possible states of those members, that members cannot combine with each other.

您能想象有3个骰子(在这种情况下,所有3面),我想通过抛出所有可能对骰子(dice1得到所有可能的组合我得到得+ dice2相同dice2 + dice1,所以我不不想这一点)。我不知道有多少骰子我将和多少面我都会有。

You can imagine having 3 dices (in this case all 3 sided ) and i want to get all possible combinations i get get by throwing all possible pairs of dices (dice1 + dice2 is the same as dice2 + dice1, so i don't want that). I don't know how many dices i will have and how many sides i will have.

任何指针,开始建议或任何东西很多AP preciated,谢谢

Any pointers, starting advice or anything is much appreciated, thank you

推荐答案

要下手,你可以做这样的事情。只是一个解决方案,在时间复杂度没有那么大。

To start with, you can do something like this. Just a solution, not so great in time complexity.

    for(int i=0; i < x.length; i++){  // Selects one dice
        for(int j = i + 1; j < x.length; j++){  // Select another dice
            for(int k=0; k<x[i].length; k++){  // selects face of first dice
                for(int l=0; l<x[j].length; l++){  // select face of 2nd dice
                    System.out.print("Dice " + i + " Face " + k + " vs Dice " + j + " Face " + l);
                    System.out.println(" ==> " + x[i][k]+ " - " + x[j][l]);
                }
            }
        }
    }

这篇关于数组成员的Java数组的组合(骰子滚?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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