Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*1
- sa se genereze toate sirusile de lungime n formate numai din A si M
- produs cartezian
- fara A langa A
- */
- #include <iostream>
- #include <cstdio>
- #include <stdlib.h>
- using namespace std;
- int N, x[20];
- char val[3];
- void afisare()
- {
- for (int i=1; i<=N; i++)
- printf ("%c ", val[x[i]]);
- printf("\n");
- }
- int valid(int k)
- {
- if (k > 1 && x[k-1]==1 && x[k]==1)
- return 0;
- return 1;
- }
- void back(int k)
- {
- if (k==N+1)
- afisare();
- else
- for(x[k]=1; x[k]<=2; x[k]++)
- if(valid(k))
- back(k+1);
- }
- int main()
- {
- scanf("%d", &N);
- val[1]='A';
- val[2]='M';
- back(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement