public class test2 {
public static int longest(String s){
int len = s.length();
int [][]dp = new int[len][len];
for(int i = len - 1;i >= 0;i--){
dp[i][i] = 1;
for(int j = i + 1; j < len; j++){
if(s.charAt(i) == s.charAt(j)){
dp[i][j] = dp[i+1][j-1] + 2;
}else{
dp[i][j] = Math.max(dp[i+1][j],dp[i][j-1]);
}
}
}
return dp[0][len-1];
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String input = in.nextLine();
System.out.println(longest(input));
}
}
}
516最长回文子序列
最新推荐文章于 2024-02-21 15:40:33 发布