Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NMAX 6
- void display(int arr[]) {
- for (int i = 0; i < NMAX; i++) {
- printf("%d", arr[i]);
- }
- puts("");
- }
- int frok(int arr[]) {
- int fr[2] = {0, 0};
- for (int i = 0; i < NMAX; i++) {
- fr[arr[i]]++;
- }//*/
- return (fr[0] == 2 && fr[1] == 4);
- }
- void bktr(int k, int arr[]) {
- if (k == NMAX) {
- if (frok(arr))
- display(arr);
- return;
- }
- for (int i = 0; i <= 1; i++) {
- arr[k] = i;
- if ((arr[0] && arr[1]) || (arr[k] == 0 && k == NMAX - 1)) {
- continue;
- }
- bktr(k + 1, arr);
- arr[k] = 0;
- }
- }
- int main(void) {
- static int arr[NMAX];
- bktr(0, arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement