Maximize count of indices with same element by pairing rows from given Matrices | C ++ program for the above approach ; Function to find the maximum score ; Stores the maximum sum of scores ; For each permutation of pos vector calculate the score ; If values at current indexes are same then increment the current score ; Print the maximum score ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxScoreSum ( vector < vector < int > > & a , vector < vector < int > > & b ) { int maxSum = 0 ; vector < int > pos ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { pos . push_back ( i ) ; } do { int curSum = 0 ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { for ( int j = 0 ; j < a [ pos [ i ] ] . size ( ) ; j ++ ) { curSum += ( a [ pos [ i ] ] [ j ] == b [ i ] [ j ] ) ; maxSum = max ( maxSum , curSum ) ; } } } while ( next_permutation ( pos . begin ( ) , pos . end ( ) ) ) ; cout << maxSum ; } int main ( ) { int N = 3 , M = 3 ; vector < vector < int > > a = { { 1 , 1 , 0 } , { 1 , 0 , 1 } , { 0 , 0 , 1 } } ; vector < vector < int > > b = { { 1 , 0 , 0 } , { 0 , 0 , 1 } , { 1 , 1 , 0 } } ; maxScoreSum ( a , b ) ; return 0 ; }