void solveDLX(int k) { int i, j, r, c, mini, mins, col; if(!R[0]) { DLXsolution(); found = 1; return; } mini = R[0]; mins = S[R[0]]; for(i = R[R[0]]; i != 0; i = R[i]) { if(S[i] < mins) { mins = S[i]; mini = i; } } col = mini; if(mins == 0) return; coverCol(col); for(r = D[col]; r != col; r = D[r]) { solution[k] = r; for(c = R[r]; c != r; c = R[c]) { coverCol(c); } solveDLX(k + 1); if(found) return; c = C[r]; for(j = L[r]; j != r; j = L[j]) { uncoverCol(j); } } uncoverCol(col); }
int main() { scanf("%d",&test); while(test--) { init(); readSudoku(); solveDLX(0); if(!found) puts("N"); } return 0; }
int main() { fread_unlocked(ibuff, 3000, 1, stdin); getstr(dump); test = atoi(dump); while(test--) { init(); readSudoku(); solveDLX(0); if(test) getstr(dump), *out++ = '\n'; } fwrite_unlocked(obuff, out - obuff, 1, stdout); return 0; }