[python] dp + bitmask
\nclass Solution:\n    def shortestSuperstring(self, words: List[str]) -> str:\n        rbm=[0]\n        for i in range(len(words)):rbm[0]|=(1<<i)\n        def 
```\nclass Solution:\n    def shortestSuperstring(self, words: List[str]) -> str:\n        rbm=[0]\n        for i in range(len(words)):rbm[0]|=(1<<i)\n        def isc(prev,curr):\n            i=0\n            i2=0\n            mi2=0\n            while i<len(prev):\n                i1=i\n                while i1<len(prev) and i2<len(curr) and prev[i1]==curr[i2]:\n                    i1+=1\n                    i2+=1\n                    if i1==len(prev):return True\n                i+=1\n            return False\n        \n        def geta(prev,curr):\n            i=max(0,len(prev)-len(curr)-1)\n            i2=0\n            mi2=0\n            while i<len(prev):\n                i1=i\n                i2=0\n                while i1<len(prev) and i2<len(curr) and prev[i1]==curr[i2]:\n                    i1+=1\n                    i2+=1\n                    if i1==len(prev):mi2=max(mi2,i2)\n                i+=1\n            return curr[mi2:]\n\n        gr=defaultdict(list)\n        gr[-1]=[i for i in range(len(words))]\n        for i in range(len(words)):\n            for j in range(len(words)):\n                f=isc(words[i],words[j])\n                if not f:continue\n                gr[i].append(j)\n        \n        @cache\n        def dp(bm,pi):\n            if bm==rbm[0]:\n                return "",True\n            a=""\n            x=False\n            for ni in gr[pi]:\n                k=1<<ni\n                if k&bm!=0:continue\n                if pi==-1:\n                    add=words[ni]\n                else:\n                    add=geta(words[pi],words[ni])\n                r,f=dp(bm|k,ni)\n                if not f:continue\n                if len(r)+len(add)<len(a) or not x:\n                    a=add+r\n                    x=True\n            if not x:\n                for ni in range(len(words)):\n                    k=1<<ni\n                    if k&bm!=0:continue\n                    if pi==-1:\n                        add=words[ni]\n                    else:\n                        add=geta(words[pi],words[ni])\n                    r,f=dp(bm|k,ni)\n                    if not f:continue\n                    if len(r)+len(add)<len(a) or not x:\n                        a=add+r\n                        x=True\n            return a,x\n        \n        r,_=dp(0,-1)\n        return r\n```
[]