[2020蓝桥杯B组决赛] G-游客安排

题解

  1、先按大写字母进行字符串分割。

  2、LIS 模板直接套用就行,这时就是单词而非数字,注意存储。

  想不到这一题竟然是我唯一对的一题,我也是个小人才(/(ㄒoㄒ)/~~),我想哭呀,呜呜呜~~。

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctype.h>
using namespace std;

string str;
vector <string> s; 
vector <vector <string> > ss;

// 最长单调递增子序列 
int main()
{
    cin >> str;
    // 字符串分割操作
    for (int i = 0; i < str.size(); ++i) {
        string t;
        t += str[i];
        for (int j = i + 1; j < str.size(); ++j) {
            if (isupper(str[j])) {
                i = j - 1;
                break;
            }
            t += str[j]; 
            if (j == str.size() - 1) i = j;
        }
        s.push_back(t);
    }
    // 最长上升子序列模板套用
    vector <string> mmax; 
    for (int i = 0; i < s.size(); ++i) {
        vector <string> tmp;
        // 计数最大值 
        int t = 1;
        for (int j = 0; j < i; ++j) {
            if (s[j] < s[i]) {
                if (t < ss[j].size() + 1) {
                    t = ss[j].size() + 1;
                    tmp = ss[j];
                }
            }
        }
        tmp.push_back(s[i]);
        ss.push_back(tmp);
        if (mmax.size() < tmp.size()) {
            mmax = tmp;
        }
    }
    for (int i = 0; i < mmax.size(); ++i) {
        cout << mmax[i] << endl;
    }
    return 0;
}

 

posted @ 2020-11-16 00:01  Fool_one  阅读(230)  评论(0编辑  收藏  举报