Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstring>
- using namespace std;
- int st[5], card[5], n;
- char s[4][5];
- void tipar(int k) {
- for (int i = 1; i <= k; i++)
- cout << s[i][st[i] - 1];
- cout << endl;
- }
- int valid(int k) {
- for (int i = 1; i < k; i++)
- if (s[i][st[i] - 1] == s[k][st[k] - 1])
- return 0;
- 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() {
- n = 4;
- strcpy(s[1], "aeiou"), card[1] = strlen(s[1]);
- strcpy(s[2], "prst"), card[2] = strlen(s[2]);
- strcpy(s[3], "bmrtv"), card[3] = strlen(s[3]);
- strcpy(s[4], s[1]), card[4] = card[1];
- bktr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement