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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With