Given a matrix of n rows and m columns of 1's and 0's, it is required to find out the number of pairs of rows that can be selected so that their OR is 1111....m times.
Example:
1 0 1 0 1
0 1 0 0 1
1 1 1 1 0
Answer:
2 ---> OR of row number [1,3] and [2,3]
Given n and m can be an order upto <= 3000, how efficiently can this problem be solved?
PS: I already tried with a naive O(n*n*m) method. I was thinking of a better solution.
In case you do not only want to output the number of pairs but also the pairs itself, you cannot do better than $\mathcal O(n^2m)$ in the worst case. This is because you need to read all the columns of the input anyway, hence the factor $m$, and you need to output all $\sim n^2$ pairs (in the worst case).