Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cheet(text, words):
- max_len = max([len(word) for word in words])
- dp = [True] + [False] * len(text)
- for i in range(1, len(text)+1):
- for j in range(1, min(max_len+1, i+1)):
- if dp[i-j]:
- suffix = text[i-j:i]
- if suffix in words:
- dp[i] = True
- break
- return dp[-1]
- text = input()
- n = int(input())
- words = set([input() for _ in range(n)])
- print('YES' if cheet(text, words) else 'NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement