Maximise sum of “non-overlapping” numbers from matrix

后端 未结 4 1232
有刺的猬
有刺的猬 2020-12-10 07:54

Just looking for a bit of direction, I realise that the example given is possible to solve using brute force iteration, but I am looking for a more elegant (ie. mathematical

4条回答
  •  青春惊慌失措
    2020-12-10 08:05

    This is related to the n Queens problem, except that you do not care about the diagonal and you have weighted solutions. As the Queens problem, you can solve it by (multiple) backtracking.

    I.e., once you find a solution you remember its weight, mark the soulution as invalid, and start over. The (a) solution with the highest weight wins.

提交回复
热议问题