Python Combinatorics DP
\nMost of my thought process is documented in the comments but a few things to note that I ran into during the codeing process is it matters the order of the wo
\nMost of my thought process is documented in the comments but a few things to note that I ran into during the codeing process is it matters the order of the word leet that we do for example our options for leet = 3,2,2,1 in that order while eelt = 3,3,2,1 since we can only count e once. We also have to concider that we start with 23 non \'leet\' characters to choose from but if we use up the \'l\' for example we now have 24 since \'l\' is now a non \'leet\' character. I decided to store the leet word in the number 15 where each character represents a bit postion for easy storage and use bit manipulation to update and check which characters we used.\n\n```py\nclass Solution:\n    def stringCount(self, n: int) -> int:\n        \n        #word either contains non leet character or contains leet character\n        #we have 2 cases characters left to place & characters needed \n        #we should multiply our result by number of non leet = 23 if we place a non leet\n        #we should multiply our result by leet remaining if leet 3?\n        \n        #is this 10 ** 5 * 4? 100k positions with only a decision on 4\n        #can we early return 26 ** n - i if we run out of options early?\n        #can use the leet characters again once they are used up\n        MOD = 10 ** 9 + 7\n        \n        @cache\n        def dfs(used, left):\n            \n            if used == 0:\n                return pow(26, left, MOD)\n            elif left == 0:\n                return used == 0\n            \n            count = 0\n            count += 1 if used & (1 << 1) > 0 or used & (1 << 2) > 0 else 0\n            count += 1 if used & (1 << 3) > 0 else 0 \n            count += 1 if used & (1 << 0) > 0 else 0\n\n            res = 0\n            eused = False\n            \n            #add a leet character\n            if used > 0:\n                for i in range(4):\n                    if used & (1 << i) > 0:\n                        #add an e character\n                        if i == 1 or i == 2:\n                            if eused:\n                                continue\n                            eused = True\n                        res += (dfs(used ^ (1 << i), left-1)) % MOD\n            \n            #add generic character\n            res += (dfs(used, left-1) * (23 + 3-count)) % MOD\n            \n            \n            return res % MOD\n        \n        \n        return dfs(15, n)\n        \n        #leet\n        #3,2,2,1\n        #eelt\n        #3,3,2,1\n
['Combinatorics', 'Bitmask', 'Python']