Utility function
static void copyMatrix ( int [ ] [ ] A , int [ ] [ ] B ) { int row = B . length ; int col = B [ 0 ] . length ; for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) { A [ i ] [ j ] = B [ i ] [ j ] ; } } }