function SOLVE(partially filled M) {
if (M has no empty entries) {
M is a solution
} else {
ij <- one empty position of M
// in practice, try picking one that reduces the number of
// iterations of the following loop
for (each possible value v of M[ij], subject to the constraints) {
M' <- a copy of M
M'[ij] = v
SOLVE(M')
}
}
M0 <- an empty Matrix of correct size
SOLVE(M0)
1 回答
是 . 你拥有的是system of linear equations,每行一个,每列一个; m * n个变量和m n个方程 .
如何计算(和表示)解决此类系统的解决方案集取决于您的环境 .
EDIT: 我明白了 . 有关此问题的大型实例,请参阅integer programming .
但如果矩阵和行/列总和很小,则可以通过backtracking找到所有解 . 非常高级的伪代码: