@@ -0,0 +1,941 @@
+package LongestPalindromicSubsequence;%0A%0A/**%0A * Created by kel on 31/03/2017.%0A */%0A%0A%0Apublic class Solution %7B%0A%0A    private int%5B%5D%5B%5D dp;%0A%0A    private int longestPalindromeSubseqFor(char%5B%5D chars, int l, int r) %7B%0A        if (l %3E r) return 0;%0A        if (dp%5Bl%5D%5Br%5D %3E 0) return dp%5Bl%5D%5Br%5D;%0A        if (chars%5Bl%5D == chars%5Br%5D) %7B%0A            dp%5Bl%5D%5Br%5D = longestPalindromeSubseqFor(chars, l + 1, r - 1) + 2;%0A        %7D else %7B%0A            dp%5Bl%5D%5Br%5D = Math.max(longestPalindromeSubseqFor(chars, l, r - 1),%0A                    longestPalindromeSubseqFor(chars, l + 1, r));%0A        %7D%0A        return dp%5Bl%5D%5Br%5D;%0A    %7D%0A%0A    public int longestPalindromeSubseq(String s) %7B%0A        int n = s.length();%0A        dp = new int%5Bn%5D%5Bn%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            dp%5Bi%5D%5Bi%5D = 1;%0A            for (int j = i + 1; j %3C n; j++) %7B%0A                dp%5Bi%5D%5Bj%5D = -1;%0A            %7D%0A        %7D%0A        return longestPalindromeSubseqFor(s.toCharArray(), 0, n - 1);%0A    %7D%0A%7D

516. Longest Palindromic Subsequence