3 aaa ababc abklmncdefg
1 3 7
动归,不多说,看代码:
#include<stdio.h> int dp[10001]; char s[10001]; int x; int max(int a,int b) { return a>b?a:b; } int suan(){ int res=0; int i=1,b; while(i<=x){ for(b=1;b<=i;b++) if(s[i]>s[b]) dp[i]=max(dp[i],dp[b]+1); res=max(res,dp[i]); i++; } return res; } int main(){ scanf("%d",&x); getchar(); int t=x,i; char ch; while(t--) { ch=getchar(); for(i=1;ch!='\n';i++) { s[i]=ch; dp[i]=1; ch=getchar(); } x=i-1;//这里注意要-1 printf("%d\n",suan()); } return 0; }
原文地址:http://blog.csdn.net/u014492609/article/details/40515941