Advertisement
madalinaradu

ASD Pb 3

May 26th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. /** p3 combinari n cifre binare care nu au 11 alaturat */
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<conio.h>
  5.  
  6. int sol[20], n = 6;//globale
  7. void afisare() {
  8.     for (int i = 1; i <= n; i++) {
  9.         printf("%3d", sol[i]);
  10.     }
  11.     printf("\n");
  12. }
  13.  
  14. bool valid(int k) {
  15.     //if(k>1 && sol[k] * sol[k-1])
  16.     if(k>1 && sol[k]==sol[k-1] && sol[k]==1)
  17.         return 0;
  18.     return 1;
  19. }
  20.  
  21. void bkt(int k) {
  22.     for (int i = 0; i <= 1; i++) {///i reprezinta multimea de valori posibile pe care o poate lua sol[k] = 0 .. 1
  23.         sol[k] = i;
  24.         if (valid(k)) {
  25.             if (k == n) {
  26.                 afisare();
  27.             } else
  28.                 bkt(k + 1);
  29.         }
  30.     }
  31. }
  32.  
  33. int main() {
  34.     bkt(1);
  35.     _getch();
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement