Pebbles

Source: PACNW 2007

  1. Read the problem and summarise the task requirements.

The input format is very unpleasant. We will never ask you to infer the number of test cases per file or the size of a grid by parsing the values and accounting for the whitespace. Let’s instead suppose the number of test cases is at most 100 and given in the first line of input, and that each grid is preceded by a single line containing its dimension.

  1. Choose a natural order to assign pebbles.

  2. Propose a very simple subproblem, so that if you knew the answer to all subproblems, then you could deduce the overall answer. Start with as few parameters as possible.

  3. When you are at a square, what information would let you know whether it is legal to place a pebble here?
  4. Form a recurrence between your subproblems.

  5. Analyse the time complexity of your algorithm, and estimate the running time.
  6. Implement this algorithm in code.

Unfortunately this problem isn’t available for judging.