Advertisement
STANAANDREY

sda exam 2

Jan 16th, 2024
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #define N 6
  5. int st[N] = { 1,1 };
  6.  
  7.  
  8. bool sol() {
  9.     int fr[2] = {0, 0};
  10.     for (int i = 0; i < N; i++) {
  11.  
  12.         fr[st[i]]++;
  13.     }
  14.     return fr[0] == 2 && fr[1] == 4;
  15. }
  16.  
  17. void bktr(int k) {
  18.     if (k == N - 1) {
  19.         if (!sol()) {
  20.             return;
  21.         }
  22.         for (int i = 0; i < N; i++) {
  23.             printf("%d ", st[i]);
  24.         }
  25.         puts("");
  26.         return;
  27.     }
  28.     for (int i = 0; i <= 1; i++) {
  29.         st[k] = i;
  30.         bktr(k + 1);
  31.     }
  32. }
  33.  
  34. int main(void) {
  35.     st[N - 1] = 1;
  36.     bktr(2);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement