Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

A grid has 7 rows and 7 columns (top to bottom; '.' open, '#' blocked): .....#. .#..##. ....... .###... ....... #...... ....#.. You may only move right or down, and you cannot enter a blocked cell. How many different routes lead from the top-left cell to the bottom-right cell?

  1. A. 67
  2. B. 915
  3. C. 924
  4. D. 134

Correct answer: A. 67

Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 67. Ignoring the blocks would give 924, and subtracting one per blocked cell (a common shortcut) gives 915.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic