Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** p3 combinari n cifre binare care nu au 11 alaturat */
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- int sol[20], n = 6;//globale
- void afisare() {
- for (int i = 1; i <= n; i++) {
- printf("%3d", sol[i]);
- }
- printf("\n");
- }
- bool valid(int k) {
- //if(k>1 && sol[k] * sol[k-1])
- if(k>1 && sol[k]==sol[k-1] && sol[k]==1)
- return 0;
- return 1;
- }
- void bkt(int k) {
- for (int i = 0; i <= 1; i++) {///i reprezinta multimea de valori posibile pe care o poate lua sol[k] = 0 .. 1
- sol[k] = i;
- if (valid(k)) {
- if (k == n) {
- afisare();
- } else
- bkt(k + 1);
- }
- }
- }
- int main() {
- bkt(1);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement