Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define newline '\n'
- #define ll long long
- #define uns unsigned
- #define deb(x) clog << x << ' '
- #define debnewL(x) clog << x << newline
- using namespace std;
- ///************************************
- inline void __attribute__ ((constructor)) _cfun();
- inline void _cfun()
- {
- freopen("combinari.in", "r", stdin);
- freopen("combinari.out", "w", stdout);
- ios :: sync_with_stdio(NULL);
- cin.tie(nullptr);
- cout.tie(nullptr);
- }
- ///************************************
- int n, k;
- int st[20];
- inline void display()
- {
- for (int i = 1; i <= k; i++)
- cout << st[i] << ' ';
- cout << newline;
- }
- void backtracking(int top)
- {
- if (top == k + 1)
- {
- display();
- return;
- }
- for (int i = st[top - 1] + 1; i <= n; i++)
- {
- st[top] = i;
- backtracking(top + 1);
- }
- }
- signed main()
- {
- cin >> n >> k;
- backtracking(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement