http://acm.nyist.net/JudgeOnline/problem.php?pid=17
关键在动态转移方程。
if(a[j] > a[i]) dp[j] = max(dp[i]+1, dp[j]);
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#define inf 999999999
using namespace std;
int dp[10010];
int main()
{
int n,i,j;
cin>>n;
while(n--)
{
string a;
cin>>a;
int len = a.size();
for(i = 0; i < len; i++)
dp[i] = 1;
for(i = 0; i < len; i++)
{
for(j = i + 1; j < len; j++)
if(a[j] > a[i]) dp[j] = max(dp[i]+1, dp[j]);
}
int maxx = 0;
for(i = 0; i < len; i++)
if(dp[i] > maxx) maxx = dp[i];
cout<<maxx<<endl;
}
return 0;
}