C++ recursion and memoization
```\nclass Solution {\npublic:\n    vectorlen;\n    vector>overlap;\n    vector>dp;\n    int n;\n    map, int>mp;\n    int solve(int idx, int mask){\n        if
```\nclass Solution {\npublic:\n    vector<int>len;\n    vector<vector<int>>overlap;\n    vector<vector<int>>dp;\n    int n;\n    map<pair<int, int>, int>mp;\n    int solve(int idx, int mask){\n        if(mask == (1 << n) - 1) return 0;\n        if(dp[idx][mask] != -1)return dp[idx][mask];\n        dp[idx][mask] = INT_MAX;\n        for(int i = 0; i < n; i++){\n            if((mask&(1 << i)) == 0){\n                int temp = len[i] - overlap[idx][i] + solve(i, mask|(1 << i));\n                if(temp < dp[idx][mask]){\n                    dp[idx][mask] = temp;\n                    mp[{idx, mask}] = i;\n                }\n            }\n        }\n        return dp[idx][mask];\n    }\n    string shortestSuperstring(vector<string>& A) {\n        n = A.size();\n        len.resize(n, 0);\n        overlap.resize(n, vector<int>(n, 0));\n        dp.resize(n, vector<int>((1 << n) + 1, -1));\n        for(int i = 0; i < n; i++){\n            len[i] = A[i].size();\n        }\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < n; j++){\n                if(i != j){\n                    int m = min(len[i], len[j]);\n                    for(int k = m; k >= 0; k--){\n                        if(A[i].substr(len[i] - k) == A[j].substr(0, k)){\n                            overlap[i][j] = k;\n                            break;\n                        }\n                    }\n                }\n            }\n        }\n        int mlen = INT_MAX;\n        int idx = 0;\n        for(int i = 0; i < n; i++){\n            int temp = len[i] + solve(i, (1 << i));\n            //cout<<temp<<endl;\n            if(temp < mlen){\n                mlen = temp;\n                idx = i;\n            }\n        }\n        string ans = A[idx];\n        int mask = 1 << idx;\n        for(int i = 1; i < n; i++){\n            int x = idx;\n            idx = mp[{idx, mask}];\n            ans += A[idx].substr(overlap[x][idx]);\n            mask |= (1 << idx); \n        }\n        return ans;\n    }\n};
[]