Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

def count_decomps(s):

n = len(s)

# DP table
NPS = [[{'num': 0, 'ispal': False} for _ in range(n)] for _ in range(n)]

# Base cases
for i in range(n):
NPS[i][i]['num'] = 1
NPS[i][i]['ispal'] = True

for l in range(2, n + 1):


for i in range(n - l + 1):
j=i+l-1

if s[i] == s[j]:
if l == 2 or NPS[i + 1][j - 1]['ispal']:
NPS[i][j]['num'] = NPS[i + 1][j - 1]['num'] + 1
NPS[i][j]['ispal'] = True

if not NPS[i][j]['ispal']:
NPS[i][j]['num'] = NPS[i][j - 1]['num'] + NPS[i + 1][j]['num'] - NPS[i + 1][j - 1]['num']

return NPS[0][n - 1]['num']

s = 'madam'
numberDec = count_decomps(s)
print(numberDec)

import matplotlib.pyplot as plt


import numpy as np

t = np.linspace(0, 2 * np.pi, 1000)


x = 16 * np.sin(t)**3
y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t)

plt.figure(figsize=(5, 5))
plt.plot(x, y, 'r')
plt.fill_between(x, y, color='red', alpha=0.5)
plt.xlim(-20, 20)
plt.ylim(-20, 20)
plt.xlabel('I love you the mostest <3')
plt.ylabel('<333')

plt.show()

You might also like