标签:style http color java os io for ar
3 aaa ababc abklmncdefg
1 3 7
也是到经典的DP题,另一种思路是,就a—z的一个字符串和该字符串的最长公共子序列,想想也是对的
import java.util.Arrays; import java.util.Scanner; public class NYOJ17 { public static void main(String[] args) { Scanner cin=new Scanner(System.in); int t=cin.nextInt(); while (t-->0){ char []s=cin.next().toCharArray(); int []f=new int[s.length+5]; Arrays.fill(f, 1);//初始化为1,刚开始写成0出错了 for (int i=2;i<=s.length;i++){ //int max=Integer.MIN_VALUE; for (int j=1;j<=i-1;j++){ if (s[i-1]>s[j-1] && f[i]<f[j]+1){ f[i]=f[j]+1; } } } int max=Integer.MIN_VALUE; for (int i=1;i<=s.length;i++){ if (max<f[i]) max=f[i]; } System.out.println(max); } } }
NYOJ17,单调递增最长子序列,布布扣,bubuko.com
标签:style http color java os io for ar
原文地址:http://blog.csdn.net/ieayoio/article/details/38454147