Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A grid has 6 rows and 5 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. 18
- B. 9
- C. 120
- D. 126
Correct answer: B. 9
Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 9. Ignoring the blocks would give 126, and subtracting one per blocked cell (a common shortcut) gives 120.
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
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): V–H (5), V–D (15), V–X (10), X–D (26), V–Z…
- Each cell of a grid with 5 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULR UUD ULL LUL UDU From a cell you may…
- A grid has 3 rows and 4 columns with these values (top to bottom): 1912 3838 7521 A path moves between side-adjacent cells (up, down, left…
- A directed graph with no directed cycles has arcs u→v (weight) : K→Q (2), K→N (-3), K→I (8), J→L (3), J→I (8), Q→N (7), Q→L (6), N→L (0)…
- A directed graph has the vertices A, D, J, N, P, V and the arcs N→V, N→P, N→A, V→A, D→A, P→A, A→V, A→D, A→J. How many strongly connected…
- Bellman–Ford is run from source M on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: G→D…