Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MOD = 10 ** 9 + 7
- def solveBrute(K, S):
- N = len(S)
- dp = [0] * (N + 1)
- dp[0] = 1
- for i in range(N + K):
- # dp[j] currently counts all strings of length i which contains S[:j] as a subsequence
- nextDp = [0] * (N + 1)
- for j in range(N):
- nextDp[j] += dp[j] * 25 # don't extend subsequence
- nextDp[j + 1] += dp[j] # extend subsequence
- nextDp[N] += dp[N] * 26 # max len subsequence can't be extended anymore
- dp = nextDp
- for j in range(N + 1):
- dp[j] %= MOD
- # print(dp)
- return dp[N]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement