Advertisement
STANAANDREY

gen subm cls

Nov 9th, 2020
1,859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n, st[20];
  4.  
  5. void tipar(int k) {
  6.     for (int i = 1; i <= k; i++)
  7.         cout << st[i] << ' ';
  8.     cout << '\n';
  9. }
  10.  
  11. int valid(int k) {
  12.     return 1;
  13. }
  14.  
  15. int sol(int k) {
  16.     return k <= n;
  17. }
  18.  
  19. void bktr() {
  20.     int k = 1;
  21.     st[k] = 0;
  22.     while (k > 0) {
  23.         if (st[k] < n) {
  24.             st[k]++;
  25.             if (valid(k)) {
  26.                 if (sol(k))
  27.                     tipar(k);
  28.                 k++;
  29.                 st[k] = st[k - 1];
  30.             }
  31.         }
  32.         else
  33.             k--;
  34.     }
  35. }
  36.  
  37. int main() {
  38.     cin >> n;
  39.     bktr();
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement