1 // Solve a Nurikabe puzzle.
15 if (!scanf("%d %d\n", &rcount
, &ccount
)) die("input error");
16 int board
[rcount
][ccount
];
18 for (int i
= 0; i
< rcount
; i
++) {
20 for (int j
= 0; j
< ccount
; j
++) {
22 if (c
== EOF
|| c
== '\n') die("input error");
40 board
[i
][j
] = encode(c
);
43 if (c
!= '\n') die("input error");
45 zdd_set_vmax(rcount
* ccount
);
47 // Label squares according to this scheme:
51 int vtab
[rcount
][ccount
];
52 int rtab
[zdd_vmax() + 1], ctab
[zdd_vmax() + 1];
59 if (v
> zdd_vmax()) break;
60 // If we're on the left or bottom edge:
61 if (i
== rcount
- 1 || !j
) {
62 // Try advancing to the top of the column.
66 // If it's out of bounds, move diagonally bottom-left.
75 // The state represents which squares are connected.
76 // state[i] = -2: i is not selected.
77 // state[i] = -1: i is unconnected to anything else in the state.
78 // state[i] = i - j: i is connected to j and j is the largest square less
79 // than i with this property.
80 void recurse(int v
, char* state
, int start
, int size
) {
85 if (r
- 1 < 0 || c
- 1 < 0) newsize
++;
86 char newstate
[newsize
];
87 for (int i
= 0; i
< size
; i
++) newstate
[i
] = state
[i
];
93 recurse(1, NULL
, 0, 0);