C++ || DP+Bitmask
\nclass Solution {\npublic:\n    int dp[9][(1<<8)+1];\n    int n,m;\n\n    int rec(int lev,int mask,vector<vector<int>>& st, vector<vector<int>>& mt){\n        
```\nclass Solution {\npublic:\n    int dp[9][(1<<8)+1];\n    int n,m;\n\n    int rec(int lev,int mask,vector<vector<int>>& st, vector<vector<int>>& mt){\n        if(lev==n) return 0;\n        if(dp[lev][mask]!=-1) return dp[lev][mask];\n        int ans=0;\n        for(int i=0;i<n;i++){\n            \n            if(!(mask&(1<<i))){\n                int score=0;\n                for(int j=0;j<m;j++){score+=(st[lev][j]==mt[i][j]);}\n                ans=max(ans,score+rec(lev+1,mask|(1<<i),st,mt));\n            }\n        }\n        return dp[lev][mask]=ans;\n    }\n    int maxCompatibilitySum(vector<vector<int>>& st, vector<vector<int>>& mt) {\n        n=st.size();\n        m=st[0].size();\n        memset(dp,-1,sizeof(dp));\n        return rec(0,0,st,mt);\n    }\n};```
['Dynamic Programming', 'Bitmask']