C++ TSP Solution !!!
\n    string shortestSuperstring(vector<string>& A) {\n        int N = A.size();\n        vector<vector<int>> dp(1<<N, vector<int>(N, -1)), parent(1<<N, vector<
```\n    string shortestSuperstring(vector<string>& A) {\n        int N = A.size();\n        vector<vector<int>> dp(1<<N, vector<int>(N, -1)), parent(1<<N, vector<int>(N, -1)) , dist(N, vector<int>(N, 0));\n        \n        for(int i = 0; i < N; i++) {\n            for(int j = 0; j < N; j++) {\n                if(i == j) continue;\n                for(int k = 0; k < A[i].length(); k++) {\n                    if(A[j].find(A[i].substr(k)) == 0) {\n                        dist[i][j] = A[i].length()-k;\n                        break;\n                    }\n                }\n            }\n        }\n        \n        for(int i = 0; i < N; i++) dp[1<<i][i] = 0;\n        \n        int last = -1, total = -1;\n        for(int mask = 0; mask < (1 << N); mask++) {\n            for(int i = 0; i < N; i++) {\n                if(((mask >> i)&1) == 0) continue;\n                int pmask = mask ^ (1 << i);\n                for(int j = 0; j < N; j++) {\n                    if((pmask >> j)&1 == 0) continue;\n                    \n                    if(dp[pmask][j] != -1 && dp[mask][i] < dp[pmask][j] + dist[j][i]) {\n                        dp[mask][i] = dp[pmask][j] + dist[j][i];\n                        parent[mask][i] = j;\n                    }\n                }\n                \n                if(mask == (1 << N)-1 && dp[mask][i] > total) {\n                    total = dp[mask][i];\n                    last = i;\n                }\n            }\n        }\n\n        int cur = (1 << N)-1;\n        vector<int> path;\n        while(cur != 0) {\n            path.push_back(last);\n            int prev = cur ^ (1 << last);\n            last = parent[cur][last];\n            cur = prev;\n        }\n        \n        reverse(path.begin(), path.end());\n        string res = A[path[0]];\n        for(int i = 1; i < path.size(); i++) {\n            res += A[path[i]].substr(dist[path[i-1]][path[i]]);\n        }\n        return res;\n    }\n```
[]