From fbf0ef369f17dacb7db7620ebe02593f36317bca Mon Sep 17 00:00:00 2001 From: Bilwasiva Date: Mon, 11 Oct 2021 18:56:16 +0530 Subject: [PATCH] Created longest_palindromic_subsequence.cpp Dynamic Programming based C++ program for LPS problem --- .../longest_palindromic_subsequence.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dynamic_programming/longest_palindromic_subsequence.cpp diff --git a/dynamic_programming/longest_palindromic_subsequence.cpp b/dynamic_programming/longest_palindromic_subsequence.cpp new file mode 100644 index 00000000..0a3c7ea8 --- /dev/null +++ b/dynamic_programming/longest_palindromic_subsequence.cpp @@ -0,0 +1,42 @@ +// A Dynamic Programming based C++ program for LPS problem +// Returns the length of the longest palindromic subsequence in seq +#include +#include + +int max (int x, int y) { return (x > y)? x : y; } + +int lps(char *str) +{ +int n = strlen(str); +int i, j, cl; +int L[n][n]; + +for (i = 0; i < n; i++) + L[i][i] = 1; + + for (cl=2; cl<=n; cl++) + { + for (i=0; i