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

题目链接

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

#include
using namespace std;
typedef long long ll;
const int N =200005;
const int INF =1e9+5;


ll a;
ll v;
ll t;
vector num;

//LIS O(n*log(n));
int getLISLength( int length)
{
    vector 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;iprintf("%d\n",getLISLength(num.size()));
    return 0;
}














你可能感兴趣的:(ACM-基础题)