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?

  1. A. 13
  2. B. 14
  3. C. 20
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic