Find the original matrix when largest element in a row and a column are given | C ++ implementation of the approach ; Function that prints the original matrix ; Iterate in the row ; Iterate in the column ; If previously existed an element ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define N  3 NEW_LINE #define M  7 NEW_LINE void printOriginalMatrix ( int a [ ] , int b [ ] , int mat [ N ] [ M ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) cout << min ( a [ i ] , b [ j ] ) << " ▁ " ; else cout << 0 << " ▁ " ; } cout << endl ; } } int main ( ) { int a [ ] = { 2 , 1 , 3 } ; int b [ ] = { 2 , 3 , 0 , 0 , 2 , 0 , 1 } ; int mat [ N ] [ M ] = { { 1 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 1 , 1 , 0 , 0 , 0 , 0 , 0 } } ; printOriginalMatrix ( a , b , mat ) ; return 0 ; }