Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Words ['bdc', 'dd', 'dba', 'ddc', 'ccb'] (each may be used at most once). A chain is a sequence of these words in which the first letter of every word after the first equals the last letter of the word before it. What is the largest number of words in any chain?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: A. 4
Bitmask DP over subsets gives 4. Greedily taking the first matching word from the list stops at 2, which is the trap for this question.
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
- Array A = [2, 3, 3, 4, 2, 2, 3, 5, 2]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- A trie keeps a counter at each node, and every word of the list W = ['ab', 'cc', 'ba', 'ca', 'ac', 'ba', 'cba', 'bba'] is inserted once…
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–F (1), B–E (1), B–F (1), C–D (1), D–F (1), D–G…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (14), A–F (12), B–D (12), C–D (8), C–E (1), E–F…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→E (8)…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…