Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Array A = [6, 7, 4, 1, 8, 8, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not ordered) whose values add up to exactly 18.
- A. 128
- B. 839
- C. 5
- D. 50
Correct answer: C. 5
Enumerating all subsets of indices gives 5 with sum 18. Allowing each value to be reused, as in the coin-change count, gives 839.
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
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→B (4), A→C…
- Array A = [2, 2, 4, 4, 1, 5, 2, 3, 1]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: B–D (7), A–D (7), C–D (9), D–E (3), A–C (2)…
- Directed weighted graph on vertices A, D, B, F, C (source A, target C) with edges: A→D (4); A→B (7); B→D (-6); D→C (3); B→C (1); A→C (12)…
- Directed acyclic graph on vertices A, B, C, D, E with edges A→D, A→C, D→B, D→C. Among all topological orderings (every edge goes from…
- Words ['b', 'b', 'b', 'c', 'cbca', 'aca'] are inserted in this order into an empty trie with one node per character, shared prefixes…