• 洛谷 P1020 导弹拦截 & [NOIP1999提高组](LIS,dp)


    传送门


    解题思路

    很显然的LIS板子题,找一个最长不上升子序列和最长上升子序列即可。

    关于LIS(O(n^2)和O(nlogn))

    AC代码

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cmath>
     4 #include<cstdio>
     5 #include<cstring>
     6 using namespace std;
     7 const int maxn=100005;
     8 int dp1[maxn],dp2[maxn],a[maxn],n,cnt1,cnt2;
     9 int main()
    10 {
    11     memset(dp1,0x3f,sizeof(dp1));
    12     do{
    13         n++;
    14     }while(scanf("%d",&a[n])!=EOF);
    15     n--;
    16     for(int i=1;i<=n;i++){
    17         if(a[i]<=dp1[cnt1]) dp1[++cnt1]=a[i];
    18         else dp1[upper_bound(dp1+1,dp1+cnt1+1,a[i],greater<int>())-dp1]=a[i];
    19         if(a[i]>dp2[cnt2]) dp2[++cnt2]=a[i];
    20         else dp2[lower_bound(dp2+1,dp2+cnt2+1,a[i])-dp2]=a[i];
    21     }
    22     cout<<cnt1<<endl<<cnt2;
    23     return 0;
    24 }

    //NOIP1999提高组 t1

  • 相关阅读:
    Linux系统管理上机作业2
    Linux系统管理上机作业1
    作业
    作业
    作业2
    作业
    作业
    第三章
    第二章
    第一章:计算机网络参考模型
  • 原文地址:https://www.cnblogs.com/yinyuqin/p/13823912.html
Copyright © 2020-2023  润新知