Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape (two squares in one direction and one square across). The knight may not land on the blocked squares (0,5), (1,3), (2,0), (3,0), (3,2), (4,1). It starts at (2,4) and must reach (4,4). What is the minimum number of knight moves needed?
- A. 1
- B. 2
- C. 5
- D. 4
Correct answer: D. 4
A BFS that refuses blocked squares gives 4 moves. Ignoring the blocked squares gives 2, and treating the knight like a king gives 2.
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 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 flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (1), S→B (6), C→B (9), D→A (9), D→T (8), B→D…
- A directed weighted graph has the arcs u→v (weight): Y→N (3), Y→E (9), Y→H (3), N→Y (3), N→E (4), N→H (7), E→N (15), E→A (11), H→Y (2)…
- An undirected graph has the vertices D, F, J, L, N, Y and the edges D–Y, Y–N, Y–J, N–F, F–J, J–L. In how many ways can each vertex be…
- A tree on the vertices F, I, P, S, T, W, Z has the arcs W→T, T→Z, W→S, W→F, P→T, P→I (each undirected edge is directed as shown). You may…
- Bellman–Ford is run from source J on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→J…