From f05d888a0b621ca4e99e2b0fb6e23c097006fe41 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 28 May 2024 10:29:13 +0200 Subject: Init --- progs/a610.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 progs/a610.py (limited to 'progs/a610.py') diff --git a/progs/a610.py b/progs/a610.py new file mode 100644 index 0000000..0d349ee --- /dev/null +++ b/progs/a610.py @@ -0,0 +1,15 @@ +def lps(str): + n = len(str) + L = [[0 for x in range(n)] for x in range(n)] + for i in range(n): + L[i][i] = 1 + for cl in range(2, n+1): + for i in range(n-cl+1): + j = i+cl-1 + if str[i] == str[j] and cl == 2: + L[i][j] = 2 + elif str[i] == str[j]: + L[i][j] = L[i+1][j-1] + 2 + else: + L[i][j] = max(L[i][j-1], L[i+1][j]); + return L[0][n-1] \ No newline at end of file -- cgit v1.2.3-18-g5258