Data Structures & AlgorithmsHardGATE CS · ICPC regional
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 move to any of its four side-adjacent cells. Moving in the direction of the cell's arrow costs 0; moving in any other direction costs 1. What is the minimum total cost from the top-left cell to the bottom-right cell?
- A. 6
- B. 4
- C. 12
- D. 5
Correct answer: D. 5
A 0-1 BFS (cost 0 along the arrow, 1 otherwise) gives 5. Ignoring the arrows and counting moves gives 6, and the number of cells whose arrow is not R or D gives 12.
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 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…
- A grid has 5 rows and 6 columns (top to bottom; '.' open, '#' blocked): ...... .##.#. ...... ....#. ...... You may only move right or…
- 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…