[C++]  DP + next_permutation() 100% fast
\nclass Solution {\npublic:\n\n    int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& m) {\n        vector<vector<int>>dp(s.size(),vector<int>
```\nclass Solution {\npublic:\n\n    int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& m) {\n        vector<vector<int>>dp(s.size(),vector<int>(s.size(),0));\n     \n        for(int i =0;i<s.size();i++){\n            for(int j =0;j<s.size();j++){\n                int cnt=0;\n                   for(int x =0;x<s[0].size();x++){\n                            if(s[i][x] == m[j][x])\n                               cnt++;\n                    }        \n                dp[i][j]=cnt;\n            }\n        }\n        \n        vector<int>a;\n        for(int i =0;i<s.size();i++)a.push_back(i);\n        \n        int ans=0;\n        do{\n            int res=0;\n            for(int i =0;i<dp.size();i++){\n               int sum=0;\n                for(int j =0;j<a.size();j++)sum+=dp[j][a[j]];\n                res = max(res,sum);\n            }\n            ans = max(ans,res);\n        }while(next_permutation(a.begin(),a.end()));\n        \n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C']