Generate a Matrix such that given Matrix elements are equal to Bitwise OR of all corresponding row and column elements of generated Matrix | Function to find the matrix , A [ ] [ ] satisfying the given conditions ; Store the final matrix ; Initialize all the elements of the matrix A with 1 ; Traverse the matrix B [ ] [ ] row - wise ; If B [ i ] [ j ] is equal to 0 ; Mark all the elements of ith row of A [ ] [ ] as 0 ; Mark all the elements of jth column of A [ ] [ ] as 0 ; Check if the matrix B [ ] [ ] can be made using matrix A [ ] [ ] ; Store the bitwise OR of all elements of A [ ] [ ] in ith row and jth column ; Traverse through ith row ; Traverse through jth column ; If B [ i ] [ j ] is not equal to c , pr " Not ▁ Possible " ; Print the final matrix A [ ] [ ] ; Driver Code ; Function Call
def findOriginalMatrix ( B , N , M ) : NEW_LINE INDENT A = [ [ 0 ] * M ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT A [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( B [ i ] [ j ] == 0 ) : NEW_LINE INDENT for k in range ( M ) : NEW_LINE INDENT A [ i ] [ k ] = 0 NEW_LINE DEDENT for k in range ( N ) : NEW_LINE INDENT A [ k ] [ j ] = 0 NEW_LINE DEDENT DEDENT DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT c = 0 NEW_LINE for k in range ( M ) : NEW_LINE INDENT if ( c == 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT c += A [ i ] [ k ] NEW_LINE DEDENT for k in range ( N ) : NEW_LINE INDENT if ( c == 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT c += A [ k ] [ j ] NEW_LINE DEDENT if ( c != B [ i ] [ j ] ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT print ( A [ i ] [ j ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT B = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] NEW_LINE N = len ( B ) NEW_LINE M = len ( B [ 0 ] ) NEW_LINE findOriginalMatrix ( B , N , M ) NEW_LINE