P8736 [蓝桥杯 2020 国 B] 游园安排

原题链接

题解

1.二分+dp

code

#include<bits/stdc++.h>
using namespace std;
string name[1000005],dp[1000005],st[1000005];
int main()
{
    string s;
    cin>>s;

    int cnt=0;
    for(int i=0;s[i];i++)
    {
        if(isupper(s[i])) name[++cnt]=s[i];
        else name[cnt]+=s[i];//处理字符串
    }


    int len=0;
    for(int i=1;i<=cnt;i++)
    {
        int pos=lower_bound(st+1,st+1+len,name[i])-st;//找到这个人在他包括他之前的位置
        len=max(len,pos);
        st[pos]=name[i];//name[i]要小于st[pos]
        dp[pos]=dp[pos-1]+name[i];//dp
    }

    cout<<dp[len];
    return 0;
}

posted @ 2024-03-30 22:02  纯粹的  阅读(61)  评论(0)    收藏  举报