Advertisement
STANAANDREY

sda bktr2

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