zoukankan      html  css  js  c++  java
  • E

    E - Levko and Array
    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.

    Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula:

    The less value c(a) is, the more beautiful the array is.

    It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most k array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible.

    Help Levko and calculate what minimum number c(a) he can reach.

    Input

    The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). The second line contains space-separated integers a1, a2, ... , an ( - 109 ≤ ai ≤ 109).

    Output

    A single number — the minimum value of c(a) Levko can get.

    Sample Input

    Input
    5 2
    4 7 4 7 4
    Output
    0
    Input
    3 1
    -100 0 100
    Output
    100
    Input
    6 3
    1 2 3 7 8 9
    Output
    1

     dp[i]代表前i个数里面至少要修改多少个数才会符合要求

     
    const int maxn = 30000;
    LL a[maxn];
    LL c[maxn];
    LL dp[maxn];
    int n,t;
    bool ok(LL x)
    {
        repf(i,1,n)
        {
            dp[i] = i - 1;
            repf(j,1,i-1)
                if(abs(a[i] - a[j]) <= x*(i - j))
                    dp[i] = min(dp[i],dp[j] + i - j - 1);
            if(dp[i]+n-i<=t)return true;
        } 
        return dp[n] <= t;
    }
        
    int main() 
    {
        while(cin>>n>>t)
        {
            repf(i,1,n) scanf("%I64d",&a[i]);
            LL Max = 0;
            repf(i,2,n) c[i] = a[i] - a[i - 1],Max = max(Max,abs(c[i]));
            LL L = 0;
            LL R = Max;
            LL ans = Max;
            while(L <= R)
            {
                LL mid = (L + R)/2;
                if(ok(mid))
                {
                    ans = mid;
                    R = mid - 1;
                }else L = mid + 1;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Lab IGMP
    IGMP知识要点
    15、通过例子讲解逻辑地址转换为物理地址的基本过程
    14、一个程序从开始运行到结束的完整过程,你能说出来多少?
    13、进程状态的切换你知道多少?
    12、虚拟技术你了解吗?
    11、动态分区分配算法有哪几种?可以分别说说吗?
    线程池
    10、内存交换和覆盖有什么区别?
    9、如果系统中具有快表后,那么地址的转换过程变成什么样了?
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3455723.html
Copyright © 2011-2022 走看看