です。私はいくつかの擬似コードでそれを撮影してみましょう。
Function MinPaints(Matrix) Returns Integer
If the matrix is empty return 0
Find all rows and columns which have a single color
If there are none, return infinity, since there is no solution
Set the current minimum to infinity
For each row or column with single color:
Remove the row/column from the matrix
Call MinPaints with the new matrix
If the result is less than the current minimum, set the current minimum to the result
End loop
Return the current minimum + 1
End Function
私はあなたの問題を解決すると思いますが、私は最適化など何も試していません。これは十分に速くないかもしれませんが、わかりません。私は、この問題がサブ指数関数的な時間で解けることを疑う。ここで
は、このアルゴリズムは、例を解決する方法を次のとおりです。
BBB
BRR
BGG
|
+---BRR
| BGG
| |
| +---RR
| | GG
| | |
| | +---GG
| | | |
| | | +---[]
| | | | |
| | | | Solvable in 0
| | | |
| | | Solvable in 1
| | |
| | +---RR
| | | |
| | | +---[]
| | | | |
| | | | Solvable in 0
| | | |
| | | Solvable in 1
| | |
| | Solvable in 2
| |
| Solvable in 3
| BB
+---Another branch with RR ...
| GG
Solvable in 4
あなたはより多くの背景を与えることができますか?特に予想されるボードサイズは何ですか?あなたはどんな複雑さを期待していますか? – amit
@amitはい、そうです。ボードは最大で50 x 50で、色数は最大で10です。 – Michael
実現可能性については何かを述べるべきです。明らかに、どこでも同じ色の単一行または列のないボードは解決できません。 – flodel