Rewrite the official solution in C++
Just rewrite the official solution in C++\n\n\nstring shortestSuperstring(vector<string>& A) {\n        int n = A.size();\n        \n        vector<vector<int>>
Just rewrite the official solution in C++\n\n```\nstring shortestSuperstring(vector<string>& A) {\n        int n = A.size();\n        \n        vector<vector<int>> overlaps(n, vector<int>(n));\n        for (int i = 0; i < n; ++i) {\n            for (int j = 0; j < n; ++j) {\n                int m = min(A[i].size(), A[j].size());\n                for (int k = m; k >= 0; --k) {\n                    if (A[i].substr(A[i].size() - k) == A[j].substr(0, k)) {\n                        overlaps[i][j] = k;\n                        break;\n                    }\n                }\n            }\n        }\n  \n        // dp[mask][i] = most overlap with mask, ending with ith element (ith \u4E5F\u5305\u542B\u5728\u4E86mask\u91CC\u9762)\n        vector<vector<int>> dp(1<<n, vector<int>(n, 0));\n        vector<vector<int>> parent(1<<n, vector<int>(n, -1));\n        \n        for (int mask = 0; mask < (1<<n); ++mask) {\n            //\u4EE5\u4E0B\u5FAA\u73AF\u662F\u4E3A\u4E86\u8BA1\u7B97dp[mask][bit]\n            for (int bit = 0; bit < n; ++bit) {\n                if (((mask>>bit)&1) > 0) {//\u8BF4\u660Ebit\u4F4D\u5728mask\u91CC\u9762\uFF0C\u6B64\u65F6dp[mask][bit]\u624D\u6709\u610F\u4E49\n                    int pmask = mask^(1<<bit);//\u8FD9\u4E00\u6B65\u662F\u4E3A\u4E86\u628Abit\u4F4D\u4ECEmask\u91CC\u9762\u53BB\u6389\n                    if (pmask == 0) continue;//\u5982\u679Cmask\u91CC\u9762\u53EA\u6709\u4E00\u4E2A\u8BCD\uFF0C\u90A3\u4E48\u8DF3\u8FC7\n                    for (int i = 0; i < n; ++i) {\n                        if (((pmask>>i)&1) > 0) {//\u5982\u679Cpmask\u91CC\u9762\u5305\u542B\u4E86\u7B2Ci\u4F4D\uFF0C\u90A3\u4E48\u8BA1\u7B97\u4EE5i\u7ED3\u5C3E\u7684pmask\uFF0C\u518D\u63A5\u4E0Abit\u4F4D\n                            int val = dp[pmask][i] + overlaps[i][bit];\n                            if (val > dp[mask][bit]) {//\u5982\u679C\u65B0\u7B97\u51FA\u6765\u7684overlap\u6BD4\u8F83\u5927\uFF0C\u90A3\u4E48\u66FF\u6362\u539F\u6709overlap\n                                dp[mask][bit] = val;\n                                parent[mask][bit] = i;//\u4FDD\u5B58\u8FD9\u79CD\u60C5\u51B5\u4E0B\u4EE5bit\u7ED3\u5C3E\u7684\u524D\u4E00\u4E2A\u8BCD\u3002\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        \n        vector<int> perm;\n        vector<bool> seen(n);\n        int mask = (1<<n) - 1;\n        \n        int p = 0;//\u5148\u8BA1\u7B97\u51FA\u7B54\u6848\u7684\u6700\u540E\u4E00\u4E2A\u5355\u8BCD\n        for (int i = 0; i < n; ++i) {\n            if (dp[(1<<n) - 1][i] > dp[(1<<n) - 1][p]) {\n                p = i;\n            }\n        }\n        \n        //\u901A\u8FC7parent\u6570\u7EC4\u4F9D\u6B21\u56DE\u6EAF\u51FA\u6700\u540E\u4E00\u4E2A\u5355\u8BCD\u662Fp\u8FD9\u79CD\u60C5\u51B5\u4E0B\uFF0C\u524D\u9762\u6240\u6709\u7684\u6392\u5217\n        while (p != -1) {\n            perm.push_back(p);\n            seen[p] = true;\n            int p2 = parent[mask][p];\n            mask ^= (1<<p);//\u4ECEmask\u91CC\u9762\u79FB\u8D70p\n            p = p2;\n        }\n        \n        //\u7531\u4E8E\u56DE\u6EAF\u51FA\u6765\u7684\u662F\u53CD\u7684\uFF0C\u5012\u4E00\u4E0B\n        reverse(perm.begin(), perm.end());\n        \n        //\u52A0\u4E0A\u6CA1\u6709\u51FA\u73B0\u7684\u5355\u8BCD\n        for (int i = 0; i < n; ++i) {\n            if (!seen[i]) {\n                perm.push_back(i);\n            }\n        }\n        \n        string ans = A[perm[0]];\n        for (int i = 1; i < n; ++i) {\n            int overlap = overlaps[perm[i - 1]][perm[i]];\n            ans += A[perm[i]].substr(overlap);\n        }\n        \n        return ans;\n        \n    }\n```\n
[]