回答編集履歴
1
コードを追加
test
CHANGED
@@ -15,3 +15,99 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
になりませんか.
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
↑の話を愚直に書いてみました.
|
26
|
+
|
27
|
+
```C#
|
28
|
+
|
29
|
+
//Lの要素が重複していなければ表示する
|
30
|
+
|
31
|
+
static void TestAndOutput( int[] L )
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
var C = new bool[ L.Count() ]; //all false
|
36
|
+
|
37
|
+
foreach( int v in L )
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
if( C[v] )return;
|
42
|
+
|
43
|
+
C[v] = true;
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
foreach( int v in L ){ Console.Write( " {0}",v ); }
|
48
|
+
|
49
|
+
Console.WriteLine();
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
//kが入力値.
|
56
|
+
|
57
|
+
static void OutputAllCombination( int k )
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
var L = new int[k]; //all 0
|
62
|
+
|
63
|
+
while( true )
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
TestAndOutput( L );
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
int p = 0;
|
72
|
+
|
73
|
+
while( true )
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
if( L[p]+1<k )
|
78
|
+
|
79
|
+
{ ++L[p]; break; }
|
80
|
+
|
81
|
+
else
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
L[p] = 0;
|
86
|
+
|
87
|
+
++p;
|
88
|
+
|
89
|
+
if( p == k )return;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
//Main
|
102
|
+
|
103
|
+
static void Main(string[] args)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
OutputAllCombination(3);
|
108
|
+
|
109
|
+
Console.Read();
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
```
|