Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define newline '\n'
- using namespace std;
- ifstream fin("text.in");
- ofstream fout("text.out");
- ///**********************
- int n;
- int st[50];
- bool used[50];
- void display(int top) {
- for (int i = 1; i < top; i++)
- fout << st[i] << ' ';
- fout << newline;
- }
- void backTr(int top, int sum) {
- if (sum >= n) {
- if (sum == n)
- display(top);
- return;
- }
- for (int i = 1; i <= n; i++)
- if (!used[i]) {
- st[top] = i;
- used[i] = true;
- backTr(top + 1, sum + i);
- used[i] = false;
- }
- }
- int main() {
- fin >> n;
- backTr(1, 0);
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement