Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [5, 6, 5, 4, 3, 8, 4, 6] (indices 0 to 7). Count the non-empty subsets of positions (each position used at most once, subsets not ordered) whose values add up to exactly 19.
- A. 13
- B. 144
- C. 115
- D. 256
Correct answer: A. 13
Enumerating all subsets of indices gives 13 with sum 19. Allowing each value to be reused, as in the coin-change count, gives 144.
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
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 / 1 5 3. Goal board: 1 2 3 / 4 5 . A move slides a…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–F (1), B–D (1), C–D (1), C–F (1), D–E (1), D–F (1) (weights…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (1), A–D (3), A–E (1), B–C (2), B–D (2), C–D (2). An edge is…
- Strings a = "baabbc" and b = "accca". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Points A(5,7), B(2,4), C(3,8), D(5,0), E(1,1), F(9,8) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: B→C (-3); D→A (-1); D→E (-2); A→E (6); B→A (-2)…