Online C++ Compiler

#include<iostream> #include<vector> #define K 16 using namespace std; vector<string> table[K][K]; void getCombinations(int k) { string str = ""; for (int bit = 0; bit <= k; bit++) { table[bit][0].push_back(str); str = str + "0"; } for (int bit = 1; bit <= k; bit++) { for (int n = 1; n <= bit; n++) { for (string str : table[bit - 1][n]) table[bit][n].push_back("0" + str); for (string str : table[bit - 1][n - 1]) table[bit][n].push_back("1" + str); } } for (int n = 1; n <= k; n++) { for (string str : table[k][n]) cout << str << " "; cout << endl; } } int main() { int k = 4; getCombinations(k); }