Boxer's blog

By Boxer, 9 years ago, In English

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.

Link

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think BFS will work, because there are not too many different board states.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      9 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        9 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        In fact the sample input runs so slow . I think that the number of states it's huge.

        • »
          »
          »
          »
          »
          9 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          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

        • »
          »
          »
          »
          »
          9 years ago, # ^ |
          Rev. 2   Vote: I like it +3 Vote: I do not like it

          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.

          • »
            »
            »
            »
            »
            »
            9 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I also suspect this with my backtracking aprouch without prunning

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Simple prunning that helps a lot — you definitely can't solve a board where you have only one object of some type left.