jainpavbhaji's blog

By jainpavbhaji, history, 12 months ago, In English

Can anyone help with the below problem statement?

I want to find the maximum sum in a 2D matrix such that:

  1. You can pick only 1 element from each row
  2. You cannot pick a column that has been picked before.

Example:

matrix = [ [12, 1, 1, 1], [13, 10, 1, 1], [40, 1, 1, 12] ]

Solution:

We pick 12 from 1st row

Now we cannot pick 13 from 2nd row as the column has already been used. Therefore, will pick 10 in 2nd row

Now we can either pick 1 or 12 from 3rd row as 1st and 2nd columns have already been used. We will pick 12 in 3rd row

So, sum = 12 + 10 + 12 = 34

This is not the maximum answer.

Max. answer = 1 + 10 + 40 = 51.

Can we solve this using Hungarian algorithm? Are there any better options? Kindly help.

Note: This is not a problem of any ongoing contest.

Full text and comments »

  • Vote: I like it
  • +11
  • Vote: I do not like it

By jainpavbhaji, history, 4 years ago, In English

I recently solved the problem of Codeforces round 146.

This is the problem statement

C++17 submission: AC submission

C++14 submission: WA submission

Both the codes are exactly same but the verdict is different.

Can anyone explain why this happens?

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it