Answer the question
In order to leave comments, you need to log in
How to optimize searching for a combination of rows and columns in a matrix?
Given a matrix of ones and zeros. It is necessary to choose such a combination of columns and rows in it in order to maximize the ratio of the number of cells with "1" to the number of cells with "0". In this case, the more rows and columns involved, the better.
For example, here rows (0,1,3) with columns (0,3,5) give only one "0" for eight "1":
1 0 0 1 0 1
1 1 0 1 1 1
0 1 0 1 0 0
1 1 0 0 0 1
Answer the question
In order to leave comments, you need to log in
I didn't test it, but something like this:
1. We consider the sum of all values of the matrix N, as well as the sum for each row and column M[] and the ratio 1 to 0 Z;
2. Subtract from N the minimum value among M: N -= min(M).;
3. "Remove" the row or column corresponding to min(M) from the matrix: subtract from each column or row (respectively) the values at the intersection and update Z in parallel;
4. Compare Z with the previous value. If it has become more, return to step 2. If less, the combination has been found (undeleted rows and columns).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question