C++ 20 line solution, O(n^2*2^n), Concise. Big Money.
A variant of the others, not original idea and I tried my best to make it shorter without hampering readability. \nThe vector<vector<string>> can be replaced by
A variant of the others, not original idea and I tried my best to make it shorter without hampering readability. \nThe `vector<vector<string>>` can be replaced by `vector<vector<int>> index` of word and a `vector<vector<int>> lengthsofar` that counts the current shortest length of the string that was formed with the bits that are represented in the "1<<n" expression.\n```\nclass Solution {\npublic:\n    string shortestSuperstring(vector<string>& A) {\n        int n = A.size();\n        vector<vector<string>> dp(1<<n,vector<string>(n));\n        vector<vector<int>> cost(n,vector<int>(n,0));\n        for(int i = 0;i<n;i++) for(int j = 0;j<n;j++) if(i!=j){\n            for(int k = min(A[i].size(),A[j].size());k>0;k--) if(A[i].substr(A[i].size()-k) == A[j].substr(0,k)){\n                cost[i][j] = k; break;\n            }\n        }\n        for(int i = 0;i<n;i++) dp[1<<i][i]+=A[i];\n        for(int o = 1;o<1<<n;++o){\n            for(int i = 0;i<n;i++) if(o&(1<<i)){\n                for(int j = 0;j<n;j++) if(i!=j && o&(1<<j)){\n                    string temp = dp[o^(1<<i)][j]+A[i].substr(cost[j][i]);\n                    if(dp[o][i].empty() || temp.size()<dp[o][i].size()) dp[o][i] = temp;\n                }\n            }\n        }\n        int last = (1<<n)-1;\n        string res = dp[last][0];\n        for(auto i:dp[last]) if(res.size()>i.size()) res = i;\n        return res;\n    }\n};\n```\n\n\n
[]