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