The Heaviest Non-decreasing Subsequence Problem 最长非递减子序列 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛

来源:互联网 发布:求矩阵 a 3 1 100 编辑:程序博客网 时间:2024/06/13 06:37

题目链接

根据题意,把值变换成数的个数,这样就变成了求最长非递减子序列,这里用O(n*log(n))的办法

#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N =200005;const int INF =1e9+5;ll a;ll v;ll t;vector<ll> num;//LIS O(n*log(n));int getLISLength( int length){    vector<ll> ivec;    ivec.clear();    for(int i = 0; i < length; ++i)    {        if (ivec.size() == 0 || ivec.back() <= num[i])            ivec.push_back(num[i]);        else        {            int low = upper_bound(ivec.begin(),ivec.end(),num[i])-ivec.begin();            ivec[low] =num[i];        }    }    return ivec.size();}int main(){//    freopen("data.txt","r",stdin);//    freopen("out.txt","w",stdout);//    ios_base::sync_with_stdio(false);    num.clear();    while(~scanf("%lld",&t))    {        a = t;        if(t<0)        {            v = 0;        }        else if(t>=10000)        {            v = 5;            a -= 10000;        }        else        {            v = 1;        }        for(int i=0;i<v;i++)        {            num.push_back(a);        }    }    printf("%d\n",getLISLength(num.size()));    return 0;}
阅读全文
0 0