Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding The Max of sum of elements in matrix in distinct rows and columns

I have a nxm matrix and I need to find the maximum of sum of its values in distinct rows and columns.

For example considering the following Matrix:

      m1 m2 m3
n1    1  2  3
n2    4  5  6
n3    7  8  9
n4    10 11 12

The max will be 12+8+4 = 24

Note that finding the max and eliminating all values belonging to that column or row is not a good solution as it doesn't work for all cases.

The exception for above will be the following:

     m1  m2
n1   17  1
n2   18  15 

If you find 18 and remove 17 and 15, the sum will be 18+1 = 19. while 17+15 = 32 has a higher value.

Any idea about the algorithm for this question?

like image 647
mohi666 Avatar asked Aug 31 '10 03:08

mohi666


People also ask

How do you find the maximum sum of the row in a matrix?

Given a matrix, find the maximum sum we can have by selecting just one element from every row. Condition is element selected from nth row must be strictly greater than element from (n-1)th row, else no element must be taken from row. Print the sum if possible else print -1.

How do you find the sum of all elements in a matrix?

Description. S = sum( A ) returns the sum of the elements of A along the first array dimension whose size does not equal 1. If A is a vector, then sum(A) returns the sum of the elements. If A is a matrix, then sum(A) returns a row vector containing the sum of each column.

How do you find the sum of each row?

To add up the numbers in a column or row, use the Formula command. Click the table cell where you want your result. On the Layout tab next to the Table Design tab, select Formula. Check between the parentheses to make sure Word includes the cells you want in the sum.


1 Answers

The solution is to use Hungarian Algorithm. It's a complicated algorithm. There's a very good lecture on that on youtube:

http://www.youtube.com/watch?v=BUGIhEecipE

like image 192
mohi666 Avatar answered Nov 15 '22 11:11

mohi666