-
Notifications
You must be signed in to change notification settings - Fork 0
/
1220.py
36 lines (29 loc) · 1015 Bytes
/
1220.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution:
def countVowelPermutation(self, n: int) -> int:
MOD = 10 ** 9 + 7
letters = ['a','e','i','o','u']
@cache
def dp(letter, remain):
if remain == 0:
return 1
ways = 0
if letter == 'a':
for option in ['e']:
ways += dp(option, remain-1)
elif letter == 'e':
for option in ['a','i']:
ways += dp(option, remain-1)
elif letter == 'i':
for option in ['a','e', 'o', 'u']:
ways += dp(option, remain-1)
elif letter == 'o':
for option in ['i', 'u']:
ways += dp(option, remain-1)
elif letter =='u':
for option in ['a']:
ways += dp(option, remain-1)
return ways % MOD
res = 0
for letter in letters:
res += dp(letter, n-1) % MOD
return res % MOD