n 個の要素の配列があります。それらの 2 つの組み合わせすべてを長さ 2 の配列に入れる必要があります。次に例を示します。
櫛が2次元配列であるとします。
n = 1,2,3
私はすべての2つの組み合わせをcomb [i] [j]に入れる必要があります:
comb[0][0] = {1}
comb[0][1] = {2}
comb[1][0] = {1}
comb[1][1] = {3}
comb[2][0] = {2}
comb[2][1] = {3}
コードの書き方がわからない!ありがとう
私の答え:
O(n!) の答え: n = 総数 m= 可能な答えの総数
int m = 0;
for (int i = 0; i < n - 1; i++){
int first = a[i];
for(int j = i+1 ; j < n ; j++){
int second = a[j];
comb[m][0] = first;
comb[m][1] = second;
++m;
}
}