Codeforces round #210 (Div. 1) -- levko and array

Source: Internet
Author: User

Question Link

    • Question:
      N and K represent n vertices. Each vertex has a value. Note: c = max (ABS (N [I]-N [I + 1]). it is required that at most K element values in the array be changed (to any value), and the minimum value of C is obtained.
    • Analysis:
      You can divide the value of C into two parts to determine whether the current array can change the number of K to cut the number of C less than two points. DP and DP [I] can be used to determine the number of numbers that need to be changed when n [I] is not changed and the value of C <= 2.
    • Note:
      During DP, if DP [I]-> DP [J] can be transferred, DP [J] = min (DP [J], DP [I] + J-I + 1), that is to say, the elements between I and j are changed. This correctness can be explained as follows: if an element in the middle does not need to be changed, when DPI is transferred to this element and then to J, the answer is better than directly from I to J, so this transfer is correct.
Const int maxn = 2100; int EPT [maxn], DP [maxn]; int N, K; int check (LL max) {rep (I, n) DP [I] = I; rep (I, n) rep (J, I) if (ABS (IPT [J]-IPT [I]) <= max * (I-j) DP [I] = min (DP [I], DP [J] + I-j-1); rep (I, n) if (DP [I] + n-I-1 <= k) return true; return false;} int main () {While (~ Rii (n, k) {rep (I, n) RI (IPT [I]); ll l = 0, r = 2e9, M; while (L <= r) {M = (L + r)> 1; if (check (M) r = m-1; else l = m + 1 ;} cout <L <Endl;} return 0 ;}


Codeforces round #210 (Div. 1) -- levko and array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.