zoukankan      html  css  js  c++  java
  • Codeforces 1304D. Shortest and Longest LIS

    根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况,保证满足题意,找最长LIS,可以找补集,将每个decrease序列分成一组,找到后取反即可

    #include<bits/stdc++.h>
    using namespace std;
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    
    vector<int> solve(int n, string s) {
        vector<int> ans(n);
        int cur = 0, i, x = n;
        while(cur < n) {
            i = cur;
            while(i < n && s[i] == '<') i++;
            for(int j = i; j >= cur; --j) ans[j] = x--;
            cur = i+1;
        }
        
        return ans;
    }
    
    void run_case() {
        string s;
        int n;
        cin >> n >> s;
        vector<int> a = solve(n, s);
        for(auto &c : s)
            c ^= '>'^'<';
        vector<int> b = solve(n, s);
        for(auto i : a) cout << i << " ";
        cout << "
    ";
        for(auto i : b) cout << n-i+1 << " ";
        cout << "
    ";
    }
     
    int main() {
        ios::sync_with_stdio(false), cin.tie(0);
        //cout.setf(ios_base::showpoint);cout.precision(10);
        int t; cin >> t;
        while(t--)
        run_case();
        cout.flush();
        return 0;
    }
    View Code
  • 相关阅读:
    读写excel文件
    数据库操作
    django项目搭建
    django基础
    string
    random函数
    vue-typescript入门
    Visual Studio 2019配置vue项目
    js css+html实现简单的日历
    python接口自动化4-绕过验证码登录(cookie)
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12316647.html
Copyright © 2011-2022 走看看