Disjoint subsequence | Bitmasking | dp | c++
\nint max_palindrome(string a)\n    {\n        int n = a.size();\n        if(n==0)\n            return 0;\n         vector<vector<int>> dp(n, vector<int>(n,0));
```\nint max_palindrome(string a)\n    {\n        int n = a.size();\n        if(n==0)\n            return 0;\n         vector<vector<int>> dp(n, vector<int>(n,0));\n        for(int i=0;i<n;i++)\n        {\n            dp[i][i] = 1;\n        }\n\t\t\n\t\t// dist is the distance between i and j pointer...\n        for(int dist = 1; dist < n;dist++)\n        {\n            for(int i = 0; i<n-1;i++)\n            {\n\t\t\t\t// j =  i +dist...\n\t\t\t\t// if j >= n, j is pointing to any valid char in string... So break...\n                if(i+dist>=n)\n                    break;\n                else\n                {\n                    int j = i+dist;\n                    if(a[i]==a[j])\n                        dp[i][j] = dp[i+1][j-1]+2;\n                    else\n                        dp[i][j] = max(dp[i][j-1],dp[i+1][j]);\n                }\n            }\n        }\n        return dp[0][n-1];\n    }\n    int maxProduct(string s) {\n        int n = s.length();\n\t\t\n\t\t// say if s = "abcd", mask = 1111, where each 1 corresponds to char at that place\n\t\t// So mask = 1011 corresponds to string "acd", neglecting \'b\' as its bit is turned off.\n\t\t\n        int mask = pow(2,n)-1;\n        long long max = 0;\n        string final_a,final_b;\n        for(int i = 0;i<=mask;i++)\n        {\n            string a="",b="";\n\t\t\t\n\t\t\t// i is mask for string a..\n\t\t\t// mask2 is for string b..\n\t\t\t\n\t\t\t// mask2 = mask^i will turn in those bits for those characters which are not in a..\n\t\t\t// like say a = "abd" then i = 1101, then mask2 will become 1111^1101 = 0010 --> c\n\t\t\t\n            int mask2 = mask^i;\n\t\t\t\n\t\t\t// constructing a...\n            for(int j=0;j<n;j++)\n            {\n                if(1<<j & i)\n                    a += s[j];\n            }\n\t\t\t//constructing b\n            for(int j=0;j<n;j++)\n            {\n                if(1<<j & mask2)\n                    b += s[j];\n            }\n\t\t\t\n\t\t\t//finding max palidrome for each subsequence...\n            long long max_a = max_palindrome(a), max_b = max_palindrome(b);\n\t\t\t\n\t\t\t\n            if(max_a*max_b > max )\n            {\n                max = max_a*max_b;\n            }\n        }\n        return max;\n    }\n```
['Dynamic Programming', 'Bitmask']