You are viewing a single comment's thread. Return to all comments →
Python iterative, code kinda self explanatory matrix i,j where i is the length of the sub array and j the start position
s = input()
n=len(s)
m=[]
for i in range(n):
u=[] for j in range(n): u.append(0) m.append(u)
for j in range(n): if(i+j==n): break if(i==0): m[i][j]=1 else: if(i==1): m[i][j]=1 if(s[j]==s[j+i]): m[i][j]=2 else: tmp=0 if(s[j]==s[j+i]): tmp=2 m[i][j]=max(m[i-2][j+1]+tmp,m[i-1][j],m[i-1][j+1])
r=0
for i in range(0,n-1):
r=max(r,m[i][0]*m[n-i-2][i+1])
print(r)
Seems like cookies are disabled on this browser, please enable them to open this website
Play with words
You are viewing a single comment's thread. Return to all comments →
Python iterative, code kinda self explanatory matrix i,j where i is the length of the sub array and j the start position
s = input()
n=len(s)
m=[]
for i in range(n):
for i in range(n):
r=0
for i in range(0,n-1):
print(r)