0和1的阵列组合组合、阵列

2023-09-11 23:25:46 作者:在泪水中成长

什么是好的算法,以填补0和1的组合阵列。 例如,如果我有三列的组合是: (1 1 1) (0 1 1) (1 0 1) (0 0 1) (1 1 0) (0 1 0) (1 0 0) (0 0 0) 它使共8行(我希望我就在这里)。 因此,如何确定行事先所需要的数量(取决于列N个),然后如何填写该数组了编程?任何编程语言是好的(我标记C和因为熟悉LISP),这是所需要的算法。谢谢

What is a good algorithm to fill an array with 0s and 1s combinations. For example if I have three columns the combinations would be: (1 1 1) (0 1 1) (1 0 1) (0 0 1) (1 1 0) (0 1 0) (1 0 0) (0 0 0) It makes a total of 8 rows (I hope I'm right here). So how to determine the needed number of rows in advance (depending on the N number of columns) and then how to fill the array out programatically? Any programming language is fine (I tagged C and lisp because of familiarity) it's the algorithm that is needed. Thanks

推荐答案

在基地从0数高达2

0 = 000
1 = 001
2 = 010
...
7 = 111