luogu#P4929. 【模板】舞蹈链(DLX)
【模板】舞蹈链(DLX)
Background
This problem is a Dancing Links template for the Exact Cover problem.
Problem Description
Given a matrix with rows and columns, each element in the matrix is either or .
You need to select some rows from the matrix so that for every column of the matrix, among the selected rows, there is one and only one row whose -th element is .
Input Format
The first line contains two integers .
The next lines each contain digits or , representing the matrix.
Output Format
Output one line containing several integers representing the answer. Separate numbers with spaces. Any feasible solution is acceptable, and the order can be arbitrary.
If there is no solution, output No Solution!.
3 3
0 0 1
1 0 0
0 1 0
2 1 3
3 3
1 0 1
1 1 0
0 1 1
No Solution!
Hint
For of the testdata, , and the number of in the matrix is guaranteed to be at most .
Translated by ChatGPT 5