Last active
April 29, 2021 03:36
-
-
Save magiskboy/25235d1e013c0452905d90e281d44f1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int v[100]; | |
int n; | |
void gen(int i) { | |
if (i == n) { | |
for (int j = 0; j < n; ++j) cout << v[j] << " "; | |
cout << "\n"; | |
return; | |
} | |
for (int j = 0; j < 2; ++j) { | |
v[i] = j; | |
gen(i+1); | |
} | |
} | |
int main() { | |
n = 3; | |
gen(0); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
vector<int> v; | |
int n; | |
void gen(int s) { | |
for (int i = 1; i < n + 1; ++i) { | |
if (s < i) { | |
for (auto x : v) cout << x << " "; | |
cout << s << "\n"; | |
return; | |
} | |
if (s > i) { | |
v.push_back(i); | |
gen(s-i); | |
v.pop_back(); | |
} | |
} | |
} | |
int main() { | |
cin >> n; | |
gen(n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment