• codeforces 360 B


    B - Levko and Array

    题目大意:给你你个长度为n的数列a,你最多改变k个值,max{ abs ( a[ i + 1] - a[ i ] ) } 的最小值为多少。

    思路:这个题很难想到如何取check。。 二分最小值,然后用dp进行check,dp[ i ]表示前 i 项中第 i 个不改变最少

    需要改变几个值。 

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PII pair<int, int>
    #define y1 skldjfskldjg
    #define y2 skldfjsklejg
    
    using namespace std;
    
    const int N = 2000 + 7;
    const int M = 1e5 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 +7;
    
    int n, k, dp[N];
    int a[N];
    
    bool check(LL mx) {
        for(int i = 1; i <= n; i++) dp[i] = i - 1;
        for(int i = 2; i <= n; i++) {
            for(int j = 1; j < i; j++) {
                if(abs(a[i] - a[j]) <= mx * (i - j)) {
                    dp[i] = min(dp[i], dp[j] + i - j - 1);
                }
            }
        }
        for(int i = 1; i <= n; i++)
            if(dp[i] + n - i <= k) return true;
        return false;
    }
    
    int main() {
        scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        LL l = 0, r = 2e9, mid, ans = 2e9;
        while(l <= r) {
            mid = l + r >> 1;
            if(check(mid)) r = mid - 1, ans = mid;
            else l = mid + 1;
        }
        printf("%d
    ", ans);
        return 0;
    }
    
    
    /*
    */
  • 相关阅读:
    sqlhelper类
    嵌入式的n个方向
    study vim + cscope
    mail lists
    关于我的学习
    yahoo enter linux mobile competition
    找工作啦 啦啦啦啦啦
    minicom display unsolicited codes
    并购的年代
    配置rt73无线网卡至suse10.3
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9466453.html
Copyright © 2020-2023  润新知