标签:style blog http io ar color os sp java
abcdefghijklmnopqrstuvwxyz
abcd efg hhh ihg
4331
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<stdlib.h> #include<algorithm> using namespace std; const int MAXN=300+5; char dic[MAXN],str[MAXN],a[MAXN]; int b[MAXN],dp[MAXN],cnt,lendic,lenstr,ans; int main() { //freopen("in.txt","r",stdin); scanf("%s",dic); getchar(); gets(str); cnt=0; lenstr=strlen(str),lendic=strlen(dic); for(int i=0;i<lendic;i++) b[dic[i]-‘a‘]=i; for(int i=0;i<=lenstr;i++) { if(str[i]==‘ ‘ || i==lenstr) { ans=0; for(int j=0;j<cnt;j++) { dp[j]=1; for(int k=0;k<j;k++) { if(b[a[k]-‘a‘]<=b[a[j]-‘a‘]) dp[j]=max(dp[j],dp[k]+1); } ans=max(ans,dp[j]); } printf("%d",ans); memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); cnt=0; } else a[cnt++]=str[i]; } return 0; }
标签:style blog http io ar color os sp java
原文地址:http://www.cnblogs.com/clliff/p/4124080.html