Data Structures & AlgorithmsVery hardICPC regional · GATE CS
Four workers (rows) and four tasks (columns) have cost matrix [[9, 2, 7, 8], [6, 4, 3, 7], [5, 8, 1, 8], [7, 6, 9, 4]], where cost[i][j] is the cost of worker i doing task j. Each worker does exactly one task and each task is done by exactly one worker. What is the minimum total cost?
- A. 13
- B. 14
- C. 20
- D. 15
Correct answer: A. 13
Bitmask DP over the set of tasks already assigned: the worker index equals the number of set bits, and dp[mask] is the cheapest way to assign those tasks. Giving each worker the cheapest task in turn is a greedy trap that can block a better overall pairing.
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
- Four cities have symmetric travel costs D = [[0, 27, 24, 21], [27, 0, 30, 17], [24, 30, 0, 1], [21, 17, 1, 0]]. Starting at city 0, you…
- 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…
- 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…