Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A directed graph on vertices 0 to 3 has adjacency matrix [[0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 0]] (adj[i][j] = 1 means an edge i→j). How many directed Hamiltonian paths (paths visiting every vertex exactly once, in any starting vertex) exist?
- A. 10
- B. 6
- C. 5
- D. 24
Correct answer: C. 5
dp[mask][v] counts paths covering the vertex set mask and ending at v, extended one edge at a time. Counting every path that uses only some vertices, or every possible permutation (24), ignores the edges that the graph actually has.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For the list [3, 5, 6, 9, 10], how many subsets (including the empty subset) have a bitwise XOR of exactly 0?
- How many subsets of the set {1, 2, ..., 10} (the empty set included) contain no two consecutive integers?
- In how many ways can 6 distinct people be divided into 3 unordered pairs (every person is in exactly one pair, and the pairs are not…
- Items are given as (weight1, weight2, value): [(2, 3, 4), (3, 4, 5), (4, 6, 2), (1, 1, 1), (5, 7, 8)]. Each item can be used once. You…
- How many ways can the six numbers [1, 2, 3, 4, 5, 6] be assigned to three labelled groups (group A, group B, group C), each number going…
- From the numbers [1, 2, 3, 5, 6, 8, 9, 10], what is the size of the largest subset in which any two chosen numbers differ by at least 2?