• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jan 28th, 2020 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. ar = ['refgrwgverwbv', 'A', 'B', 'BA', 'BAB',
2.       'BABBA', 'BABBABAB', 'BABBABABBABBA',
3.       'BABBABABBABBABABBABAB',
4.       'BABBABABBABBABABBABABBABBABABBABBA',
5.       'BABBABABBABBABABBABABBABBABABBABBABABBABABBABBABABBABAB']
6. br = [['a', 'a']]
7. s = ''
8. n = 0
9.
10.
11. def instr(a, b):
12.     if len(a) > len(b):
13.         return 0
14.     ans = 0
15.     for i in range(len(b) - len(a) + 1):
16.         if b[i:(i + len(a))] == a:
17.             ans += 1
18.     return ans
19.
20.
21. xxxx = {}
22.
23. def ans(i, ss):
24.     if xxxx.get(i) is not None:
25.         return xxxx.get(i)
26.     elif i <= 10:
27.         qwer =  instr(ss, ar[i])
28.         xxxx[i] = qwer
29.         return qwer
30.     qwer = instr(ss, br[i - 1][1] + br[i - 2][0]) + ans(i - 1, ss) + ans(i - 2, ss)
31.     xxxx[i] = qwer
32.     return qwer
33.
34.
35. n = int(input())
36. s = input()
37.
38. for i in range(1, n + 1):
39.     if i <= 10:
40.         e = ar[i][:min(len(ar[i]), len(s) - 1)]
41.         r = ar[i][-min(len(ar[i]), len(s) - 1):]
42.         br.append([e, r])
43.     else:
44.         br.append([
45.             br[i - 1][0],
46.             br[i - 2][1]
47.         ])
48.
49. print(ans(n, s))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top