Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A grid has 6 rows and 6 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?
- A. 246
- B. 32
- C. 252
- D. 16
Correct answer: D. 16
Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 16. Ignoring the blocks would give 252, and subtracting one per blocked cell (a common shortcut) gives 246.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 20. Two sequences of steps…
- A grid has 4 rows and 4 columns (top to bottom; '.' open, '#' blocked): ..## .... .... .... You may only move right or down, and you…
- An undirected connected graph on the vertices D, H, I, K, M has the edges H–K, I–K, D–H, D–M, D–K, D–I, H–M, M–K, H–I. How many spanning…
- An undirected graph has the vertices R, T, V, X and the edges T–R, T–X, T–V, R–V, X–V. A walk may repeat vertices and edges. How many…
- A connected undirected graph has the vertices B, D, J, K, Q, X and the edges X–J, X–B, X–D, J–B, J–Q, J–K, J–D, B–K, B–D. Parallel edges…
- A connected undirected graph has the vertices A, F, I, M, Q, S, X and the edges M–Q, M–S, M–A, M–X, Q–S, S–F, A–I. How many bridges does…