HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Find if there is matrix that satisfying the following conditions

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
conditionsthesatisfyingfollowingthatfindtherematrix

Problem

Given a matrix $A_{n\times n} = \{a_{ij}\}$ such that $a_{ij}$ is a non-negative number and given 2 vectors $(r_1,r_2,...,r_n)$ , $(c_1,c_2,...,c_n)$ such that $r_i,c_i\in \mathbb{Z}$ define an efficient algorithm that will determine if there's a matrix $B_{n\times n} = \{b_{ij}\}$ , $b_{ij} \in \mathbb{Z}$ and

for every $1\leq i \leq n \sum b_{ij} = r_i$

for every $1\leq j \leq n \sum b_{ij} = c_j$

and

$0 \leq b_{ij} \leq a_{ij}$

Thought something with dynamic programming but didn't manage to solve it.

Solution

Hint #1:


This can be solved with network flow.

Hint #2:


Imagine $r_i$ units of flow entering the $i$th row, and $c_j$ units of flow leaving the $j$th column. Does that give you any hints how to set up the graph for a network flow problem?

Context

StackExchange Computer Science Q#119393, answer score: 7

Revisions (0)

No revisions yet.