Блог пользователя aviral0807

Автор aviral0807, история, 5 лет назад, По-английски

I was looking for a solution to the problem to fill an nxn matrix with positive integers. Given positive integers r1, r2, ..., rn, c1, c2, ..., cn.

Where ri is the sum of the ith row and cj is the sum of the jth column.

My thoughts suggest it is somewhat similar to the sudoku problem. Still not sure as the constraints are different.

Can anyone suggest an optimal way to do so? Any heuristic algorithm to solve it is also welcomed.

Thanks.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +35 Проголосовать: не нравится

Sounds like flow, depending on bounds.

4 layers: Source -> nodes representing rows -> nodes representing columns -> sink.

Edge from source to row node i has capacity r_i.

Edge from col node j to sink has capacity c_j.

Add an edge from every row node to every col node with capacity infinity.

Run your favorite max flow algorithm.

The flow on the edge from row node i to col node j gives us the value in the matrix of element a_ij.

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

After knowing that this class of problem can be modeled by using max flow. I'm curious if a problem like this can also be modeled in such a manner?

There are three nxn matrices A, B, C. We have to fill the matrix A such that the row sum of matrix [Aij Bij] = ri, and column sum of matrix [Aij Cij] = cj. Here we are performing element-wise multiplication of AB and AC respectively.

Edit: Matrices B and C are already given to us.