Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int v[100], n;
- char st[] = { 0, 'A', 'C', 'D' };
- void Init(int k) {
- v[k] = 0;
- }
- int Succesor(int k) {
- if (v[k] < 3) {
- v[k]++;
- return 1;
- }
- return 0;
- }
- int Valid(int k) {
- return 1;
- }
- int Solution(int k) {
- return (k == n);
- }
- void Print() {
- int i;
- for (i = 1; i <= n; i++)
- printf("B%c", st[v[i]]);
- printf("\n");
- for (i = 1; i <= n; i++)
- printf("%cB", st[v[i]]);
- printf("\n");
- }
- void Back() {
- int k = 1, isS, isV;
- Init(k);
- while (k > 0) {
- isS = 0; isV = 0;
- if (k <= n)
- do {
- isS = Succesor(k);
- if (isS) isV = Valid(k);
- } while (isS && !isV);
- if (isS)
- if (Solution(k))
- Print();
- else {
- k++;
- Init(k);
- }
- else
- k--;
- }
- }
- int main() {
- printf("n = "); scanf("%d", &n);
- n /= 2;
- Back();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement