(C++) 2002. Maximum Product of the Length of Two Palindromic Subsequences
\n\nclass Solution {\npublic:\n    int maxProduct(string s) {\n        int n = s.size(); \n        vector<int> dp(1 << n); \n        for (int mask = 1; mask < (
\n```\nclass Solution {\npublic:\n    int maxProduct(string s) {\n        int n = s.size(); \n        vector<int> dp(1 << n); \n        for (int mask = 1; mask < (1 << n); ++mask) \n            if ((mask & mask-1) == 0) dp[mask] = 1; \n            else {\n                int lo = log2(mask & ~(mask-1)), hi = log2(mask); \n                if (s[lo] == s[hi]) dp[mask] = 2 + dp[mask^(1<<lo)^(1<<hi)]; \n                else dp[mask] = max(dp[mask^(1<<lo)], dp[mask^(1<<hi)]);\n            }\n        \n        int ans = 0; \n        for (int mask = 0; mask < (1 << n); ++mask) {\n            int comp = (1 << n) - 1 ^ mask; \n            ans = max(ans, dp[mask] * dp[comp]); \n        }\n        return ans; \n    }\n};\n```
['C']