The original idea of โโthe answer, which, of course, can be further improved.
You can start thinking about a way to create diagonal zeros and where rows and columns are summed with zeros. If they can be easily built, you can get your result by adding the original matrix with all of them.
eg:.
[ 0 1 -2 1; 1 0 -1 0; -1 2 0 -1; 0 -3 3 0]
You can even limit these โauxiliaryโ matrices to the maximum maximum number of 1 and one -1 on each row / column. All the rest can be built from them.
eg.
A = [ 0 -1 2 -1; 2 0 -2 0; -2 1 0 1; 0 0 0 0]; B = [ 0 -1 1 0; 1 0 -1 0; -1 1 0 0; 0 0 0 0]; C = [ 0 0 1 -1; 1 0 -1 0; -1 0 0 1; 0 0 0 0]; % A equals B+C
I think this at least slightly reduces your problem. Good luck
tvo
source share