C++ 組み合わせ　列挙

とりあえずコード

```
#include <bits/stdc++.h>
using namespace std;

int counter = 0;

void Combination(vector<int> v, int n, int r, int vIndex, vector<int> temp, int tempIndex) {
    temp.at(tempIndex) = vIndex;
    if (tempIndex < r - 1) return Combination(v, n, r, vIndex + 1, temp, tempIndex + 1);
    for (int i = 0; i < temp.size(); i++) {
        cout << temp.at(i) << ",";
    }
    cout << endl;
    counter += 1;
    if (temp.at(0) == n - r) return;
    if (vIndex == v.size() - 1) {
        for (int i = r - 1, j = n - 1; i >= 0; i--, j--) {
            if (temp[i] < j) return Combination(v, n, r, temp.at(i) + 1, temp, i);
        }
    }
    return Combination(v, n, r, vIndex + 1, temp, tempIndex);
}
int main() {
    vector<int> test = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> temp(5);
    Combination(test, test.size(), 5, 0, temp, 0);
    cout << counter << endl;
    return 0;
}
```

# 説明
正確には組み合わせ対象の配列のIndexを列挙している。
対象は重複無しであればいい。

# 実行結果
```
0,1,2,3,4,
0,1,2,3,5,
0,1,2,3,6,
0,1,2,3,7,
0,1,2,3,8,
0,1,2,3,9,
0,1,2,4,5,
0,1,2,4,6,
0,1,2,4,7,
0,1,2,4,8,
0,1,2,4,9,
0,1,2,5,6,
0,1,2,5,7,
0,1,2,5,8,
0,1,2,5,9,
0,1,2,6,7,
0,1,2,6,8,
0,1,2,6,9,
0,1,2,7,8,
0,1,2,7,9,
0,1,2,8,9,
0,1,3,4,5,
0,1,3,4,6,
0,1,3,4,7,
0,1,3,4,8,
0,1,3,4,9,
0,1,3,5,6,
0,1,3,5,7,
0,1,3,5,8,
0,1,3,5,9,
0,1,3,6,7,
0,1,3,6,8,
0,1,3,6,9,
0,1,3,7,8,
0,1,3,7,9,
0,1,3,8,9,
0,1,4,5,6,
0,1,4,5,7,
0,1,4,5,8,
0,1,4,5,9,
0,1,4,6,7,
0,1,4,6,8,
0,1,4,6,9,
0,1,4,7,8,
0,1,4,7,9,
0,1,4,8,9,
0,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