单调递增最长子序列

来源:互联网 发布:三国无双7捏脸数据 编辑:程序博客网 时间:2024/06/07 02:08

南阳理工oj

数据比较弱。。。


#include<iostream>#include<cstring>#define MAX_SIZE 10002using namespace std;char str[MAX_SIZE];int  cost[MAX_SIZE];int main(){int t;int len;cin>>t;char c;while(t--){cin>>str;memset(cost,0,sizeof(cost));len=strlen(str);    cost[len-1]=1;    c=str[len-1];    for(int j=len-2;j>=0;j--){int temp=j+1;int maxnum=0;    for(;temp<len;temp++)    {    if(str[j]<str[temp]&&cost[temp]>maxnum)    {    maxnum=cost[temp];        }        }cost[j]=maxnum+1;    }int maxnum=-1;for(int j=0;j<len;j++){//cout<<cost[j]<<" ";if(cost[j]>maxnum)maxnum=cost[j];}cout<<maxnum<<endl;}}




0 0
原创粉丝点击