Easy recursion+bitmask+memoization
\nclass Solution {\npublic:\n    int dp[9][1<<9];\n    int n,m;\n    int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& ma) {\n        m=s.siz
```\nclass Solution {\npublic:\n    int dp[9][1<<9];\n    int n,m;\n    int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& ma) {\n        m=s.size(),n=ma[0].size();\n        memset(dp,-1,sizeof(dp));\n        return fun(m,0,s,ma);\n    }\n    int fun(int i,int mask,vector<vector<int>>& s,vector<vector<int>>& ma){\n        if(i==0){\n            return 0;\n        }\n        if(dp[i][mask]!=-1) return dp[i][mask];\n        int ans=0;\n        vector<int>temp=s[i-1];\n        for(int j=0;j<m;j++){\n            int mask1=mask&(1<<j);\n            if(!mask1){\n                int sum=0;\n                for(int p=0;p<n;p++) sum+=(ma[j][p]==temp[p]);\n                ans=max(ans,sum+fun(i-1,mask|(1<<j),s,ma));\n            }\n        }\n        return dp[i][mask]=ans;\n    }\n};\n```
['Dynamic Programming', 'C']