回答編集履歴
1
リストを作るコードを追加
test
CHANGED
@@ -29,3 +29,49 @@
|
|
29
29
|
gen(5, 7, 0)
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
**追記**
|
34
|
+
|
35
|
+
リストcombination を作りたいのですね。
|
36
|
+
|
37
|
+
```Python
|
38
|
+
|
39
|
+
xk = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
combination = []
|
44
|
+
|
45
|
+
a = xk[:]
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def gen(n0, n1, i): # n0: 0 の個数, n1: 1 の個数
|
50
|
+
|
51
|
+
if n0 == 0 and n1 == 0:
|
52
|
+
|
53
|
+
combination.append(a[:])
|
54
|
+
|
55
|
+
return
|
56
|
+
|
57
|
+
if n0 > 0:
|
58
|
+
|
59
|
+
a[i] = 0
|
60
|
+
|
61
|
+
gen(n0-1, n1, i+1)
|
62
|
+
|
63
|
+
if n1 > 0:
|
64
|
+
|
65
|
+
a[i] = 1
|
66
|
+
|
67
|
+
gen(n0, n1-1, i+1)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
gen(5, 7, 0)
|
72
|
+
|
73
|
+
for e in combination:
|
74
|
+
|
75
|
+
print(e)
|
76
|
+
|
77
|
+
```
|