Codeforces 939F. cutlet-Monotone Queue Optimization DP__DP

Source: Internet
Author: User

Transmission Door :

Have 2∗n time to fry a two sides of meat, give you k can be flipped interval [Li,ri] [L I, R I] [L_i,r_i], can flip any time within the interval to ensure that the interval does not intersect
Ask if there is a legal solution that makes both sides just fry for n minutes and ask for the minimum number of flips
n<=100000,k<=100 Solution:

Consider a simple DP.

F[I][J] f [i] [j] F[i][j] represents the first I-second, the minimum number of flips required to bake a surface that is not currently roasted

Transfer f[i][j]=f[i−1][j],f[i][j]=f[i−1][i−j]+1 F [i] [j] = f [i−1] [j], F [i] [j] = f [i−1] [i−j] + 1 F I [J]=f[i-1][j],f[i][j]=f[i-1][i-j]+1

But this is O (n2) O (n 2) O (n^2), which needs to be optimized

Notice that the second shift only happens in this k interval.

Then we can change the state:

F[I][J] f [i] [j] F[i][j] represents the forward Ri R i r_i seconds, the minimum number of flips required for the current not baked surface to be roasted for j seconds

At the same time we found that the meat of each interval was flipped up to 2 times, so we could split it up and turn it over two times to discuss

The transfer is
F[i][j]=mink≤ri−lik=0 (f[i−1][j−k]) +2 f [i] [j] = m i n k = 0 K≤r i−l i (f [i−1] [j−k]) + 2 f[i][j]=min_{ K=0}^{k≤r_i-l_i} (F[i-1][j-k]) +2,

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.