Doubling principle

1) recurrence time, if the state space large linear recurrence can not meet the requirements of the complexity of time and space, by way of doubling.
2) binary recursive partitioning to any integer can be expressed as a number of items of power and 2, using the obtained representative value makes up the required
3) recurrence of the problem-solving power of the state space must be about 2 It has Demarcation

Model classic problem:
the length of a sequence of n, m interrogation times, each time a given t, the subscript k is determined such that the maximum from less than 1 to k and t, which is the most Interval Value Problems

Simple approach:
enumeration k, each asking for the worst case O (n)
two points:
pretreatment and the prefix, the location of a binary array with k O (n) time, each query is O (logn)

Multiplying practice:
1) Let p = 0, k = 0, sum = 0
Relationship between the number p and a t after 2) Comparison of the array A k,
if the sum + s [k + p] -s [k] <t, so sum + = s [k + p ] - s [k], k + = p, p * = 2
is the number p plus and accumulated, and then growing the p span twice,
if the sum + s [ k + p] -s [k] > t, orders p / = 2
. 3) repeated until p is 0

Guess you like

Origin www.cnblogs.com/hhyx/p/12432189.html