Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A grid has 5 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. 14
- B. 122
- C. 18
- D. 126
Correct answer: A. 14
Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 14. Ignoring the blocks would give 126, and subtracting one per blocked cell (a common shortcut) gives 122.
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 tree has the vertices B, D, E, G, J, O, S, W and the edges S–J, J–D, J–B, B–O, S–G, D–W, G–E. A set D dominates the tree if every vertex…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A tree has the vertices A, D, E, G, I, L, P, V, W and the edges L–G, L–W, W–P, W–A, A–E, P–D, P–I, L–V. A centroid is a vertex whose…
- A directed acyclic graph has the vertices C, G, K, P, W, X, Z and the arcs Z→X, Z→G, Z→K, C→W, C→K, P→X, P→K, X→W, W→K, G→K. Two players…
- An undirected graph has the vertices H, J, K, N, P, Q, R and the edges K–R, K–P, Q–J, N–R, P–R, N–J, P–J, K–J, Q–R, H–J. How many simple…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3} and s ≤ the pile size. The player who…