Hi everyone , i am trying to solve SCPC14 in gym and particulary i was thinking how to solve problem G i think a naive bruteforce with backtracking but it was very slow .
Can somebody give me some hints in order to solve this problem.
Thanks in advance.
I think BFS will work, because there are not too many different board states.
Believe me that using bfs inside your backtracking and searching all board states it's so slow , must have some prunning or similar in this problem.
have you tried BFS and failed? the fact that number of different colors is only 4 and the cells are shifted to left and down makes number of states very low , also you can use previously computed states in many test cases in the same test file
In fact the sample input runs so slow . I think that the number of states it's huge.
Maybe there's something wrong in your code , here's one of AC solutions code
as you can see it did nothing more than DFS with memorization to states
We have 5 x 6 board. Each column can be some subset of itself, but some subsets are unreachable. It gives higher bound to 2^30 states. Note it's a higher bound and in practice is not reachable.
I also suspect this with my backtracking aprouch without prunning
Simple prunning that helps a lot — you definitely can't solve a board where you have only one object of some type left.