zoukankan      html  css  js  c++  java
  • LIS(变形) HDOJ 5489 Removed Interval

    题目传送门

    题意:求删掉连续L长度后的LIS

    分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i]。dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1]的LIS,ans = max (dp[i] + rdp[i] - 1),还要特别考虑删去最后L的长度

    /************************************************
    * Author        :Running_Time
    * Created Time  :2015/9/29 星期二 15:11:29
    * File Name     :F.cpp
     ************************************************/
    
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <list>
    #include <map>
    #include <set>
    #include <bitset>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    
    #define lson l, mid, rt << 1
    #define rson mid + 1, r, rt << 1 | 1
    typedef long long ll;
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    const int MOD = 1e9 + 7;
    const double EPS = 1e-8;
    int a[N];
    int dp[N], rdp[N];
    int d[N];
    
    int main(void)    {
        int T, cas = 0; scanf ("%d", &T);
        while (T--) {
            int n, L;  scanf ("%d%d", &n, &L);
            for (int i=1; i<=n; ++i)    {
                scanf ("%d", &a[i]);
            }
    
            int ans = 0;
            memset (d, INF, sizeof (d));
            for (int i=n; i>=1; --i)    {
                int k = lower_bound (d+1, d+1+n, -a[i]) - d;
                d[k] = -a[i];
                rdp[i] = k;                                                                 //以a[i]为开始的LIS长度
            }
            memset (d, INF, sizeof (d));
            for (int i=1; i<=n; ++i)    {
                if (i - L - 1 >= 1) d[lower_bound (d+1, d+1+n, a[i-L-1]) - d] = a[i-L-1];
                dp[i] = lower_bound (d+1, d+1+n, a[i]) - d;                                 //以a[i]为结尾的LIS长度
                if (i > L) ans = max (ans, dp[i] + rdp[i] - 1);
            }
            if (n > L) ans = max (ans, (int) (lower_bound (d+1, d+1+n, a[n-L]) - d));       //删去最后的L长度
            printf ("Case #%d: %d
    ", ++cas, ans);
        }
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    iOS13 present VC方法
    青囊奥语
    三元九运的排盘
    三元九运 笔记
    青囊经
    金钱卦起卦
    易经中九二六三是什么意思
    用神
    六爻预测中的世爻,应爻分别代表什么
    div2-1519-D-Maximum Sum of Products-dp
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4846633.html
Copyright © 2011-2022 走看看