[C++] | [OPTIMIZED Backtracking Solution] | [Easy-To-Understand]
\nclass Solution {\npublic:\n    inline int score(vector<int> &a, vector<int> &b, int &size)\n    {\n        int s=0;\n        for(int i=0;i<size;++i)\n        
```\nclass Solution {\npublic:\n    inline int score(vector<int> &a, vector<int> &b, int &size)\n    {\n        int s=0;\n        for(int i=0;i<size;++i)\n            if(a[i]==b[i])\n                s++;\n        return s;\n    }\n    inline void solve(int arr[], vector<bool> &a, int &m, int &n, int &ms, int l, int sum)\n    {\n        if(l==m)\n            ms=max(ms,sum);\n        else if(sum+((m-l)*n)>ms)\n        {\n            for(int i=0;i<m;++i)\n            {\n                if(a[i])\n                {\n                    a[i]=0;\n                    solve(arr,a,m,n,ms,l+1,sum+arr[(l*m)+i]);\n                    a[i]=1;\n                }\n            }\n        }\n    }\n    inline int maxCompatibilitySum(vector<vector<int>>& stu, vector<vector<int>>& men) \n    {\n        ios::sync_with_stdio(0);\n        cin.tie(0);\n        cout.tie(0);\n        \n        int ms=0,m=stu.size(),n=stu[0].size(),t=m*m;\n        vector<bool> a(m,1);\n        int *arr=new int[t];\n        \n        for(int i=0;i<m;++i)\n            for(int j=0;j<m;++j)\n                arr[(i*m)+j]=score(stu[i],men[j],n);\n        \n        solve(arr,a,m,n,ms,0,0);\n        return ms;\n    }\n};\n```\n***Do Hit Upvote if you like the Solution***
['C']