Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A grid has 6 rows and 4 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. 52
- B. 56
- C. 20
- D. 10
Correct answer: D. 10
Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 10. Ignoring the blocks would give 56, and subtracting one per blocked cell (a common shortcut) gives 52.
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 bipartite graph has left side P1, P2, P3 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q5, P1–Q3, P3–Q4, P1–Q2, P2–Q1, P2–Q4, P3–Q3…
- A directed graph has the vertices E, G, Q, Z and the arcs E→Q, E→Z, G→E, G→Q, G→Z, Q→G, Q→Z, Z→E. Count the directed Hamiltonian paths…
- A grid has 4 rows and 3 columns with these values (top to bottom): 121 725 748 239 A path moves between side-adjacent cells (up, down…
- A tree has vertices with weights in brackets: A[9], J[13], P[6], Q[8], M[2], V[3], Y[6], R[8]. The edges are A–J, J–P, A–Q, Q–M, P–V, Q–Y…
- A directed graph with no directed cycles has arcs u→v (weight) : I→X (0), I→C (8), I→T (7), X→C (2), C→T (-3), T→Z (0). Weights may be…
- An undirected graph has the vertices F, J, M, S, Z and the edges Z–F, Z–J, S–F, S–M, S–J, F–J. What is its chromatic number, the least…