Advertisement
STANAANDREY

prod cart cls

Nov 3rd, 2020
1,847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int st[30], card[30], n;
  4.  
  5. void tipar(int k) {
  6.     for (int i = 1; i <= k; i++)
  7.         cout << st[i] << ' ';
  8.     cout << endl;
  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] < card[k]) {
  24.             st[k]++;
  25.             if (valid(k)) {
  26.                 if (sol(k))
  27.                     tipar(k);
  28.                 else {
  29.                     k++;
  30.                     st[k] = 0;
  31.                 }
  32.             }
  33.         }
  34.         else
  35.             k--;
  36.     }
  37. }
  38.  
  39. int main() {
  40.     cin >> n;
  41.     for (int i = 1; i <= n; i++)
  42.         cin >> card[i];
  43.     bktr();
  44.     return 0;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement