• 高兴天数---最长上升子序列思想


    题目描述

    小X性格很独特,如果她今天高兴度比上次一样或更高,她就会很善良,相反,如果她今天高兴度比上次低,她就会很凶!现在已经知道小X在N天里每天的高兴度M。根据这N天中她每天高兴度M,合理安排与她相处时间,使大家与小X友好相处尽量多天数。现在要求计算出最多能和小X友好相处多少天。

    输入

    共2行,第一行为一个N,第二行为N个数,为小X每天的高兴程度M。

    输出

    共1个数,最多能和小X友好相处多少天。

    样例输入

    5
    2 3 5 6 4 
    

    样例输出

    4
    

    提示

    对于30%的数据,N<=8000
    对于100%的数据,N,M<31000

    #pragma GCC optimize (2)
    #pragma G++ optimize (2)
    #include <bits/stdc++.h>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <string>
    #include <vector>
    using namespace std;
    #define wuyt main
    typedef long long ll;
    #define HEAP(...) priority_queue<__VA_ARGS__ >
    #define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
    template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
    template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
    //#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
    //char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
    ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
    if(c == '-')Nig = -1,c = getchar();
    while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;}
    #define read read()
    const ll inf = 1e15;
    const int maxn = 2e5 + 7;
    const int mod = 1e9 + 7;
    #define start int wuyt()
    #define end return 0
    int a[maxn];
    int shu[maxn];
    start
    {
        int n=read,ans=0;
        memset(a,0x3f3f3f3f,sizeof(a));
        for(int i=1;i<=n;i++)
            shu[i]=read;
        for(int i=1;i<=n;i++)
        {
            int temp=upper_bound(a+1,a+n+1,shu[i])-a;
            a[temp]=shu[i];
            ans=max(ans,temp);
        }
        cout<<ans<<endl;
        end;
    }
    
  • 相关阅读:
    git 查看远程分支、本地分支、删除本地分支
    iOS edgesForExtendedLayout、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets属性详解
    【iOS开发】UIWebView与JavaScript(JS) 回调交互
    iOS打印Debug日志的方式
    iOS项目上传到AppStore步骤流程
    IOS开发之实现App消息推送(最新)
    DKNightVersion 的实现 --- 如何为 iOS 应用添加夜间模式
    用Session实现验证码
    HTTP中Get与Post、ViewState 原理
    ASP.NET获取服务器文件的物理路径
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144194.html
Copyright © 2020-2023  润新知