Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int st[30], card[30], n;
- void tipar(int k) {
- for (int i = 1; i <= k; i++)
- cout << st[i] << ' ';
- cout << endl;
- }
- int valid(int k) {
- return 1;
- }
- int sol(int k) {
- return k == n;
- }
- void bktr() {
- int k = 1;
- st[k] = 0;
- while (k > 0) {
- if (st[k] < card[k]) {
- st[k]++;
- if (valid(k)) {
- if (sol(k))
- tipar(k);
- else {
- k++;
- st[k] = 0;
- }
- }
- }
- else
- k--;
- }
- }
- int main() {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> card[i];
- bktr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement