[HDU4734] F (x) (dp + digital optimization)

> Portal <
title meaning: For a n -bit (which n bits are from high to low A n , A n-. 1 , A n-2  ... A 2 , A . 1 ) of the decimal number, which we define the weight F. (X) = a n- * 2 n--. 1  + a n--. 1 * 2 n--2  + ... + a 2 * a + 2 . 1 *. 1. you are given two numbers a , B , calculate [0, B] the number of weights in the range of <= F. (a) number of

Ideas :( The following text is a bit much, I may be too weak at the beginning to learn the only way I can understand ~ QAQ )

In fact, F (x) just to each digit Bring a weight v = 2 ^ (the p--1) , F (x) maximum value is not more than 5,000, we can put aside the weights to think, write code when coupled with the weights can be, so to think and write drafts and the like will be a lot easier, if not consider each of the weight that is the prefix and the number of bits.

It is easy to think of a dp style is dp [pos] [sum] ; indicates that the current at the pos position, prefixes, and for the sum of answers, quick to digital dp Qiaowan, pay up, then find TLE out, limit this question only 500ms, TLE what the reason is, that is the memory of not thorough enough .

In doing digital dp entry title  not 62 may be a bit when people will pay attention, dp array initialized only once, this is not because 62 is not included in the meaning of the title and number of the four consecutive 62 numbers, conditions here is a number very nature, that is, there a number of 4 or 62 consecutive you enter and [l, r] section is irrelevant, such as 1234 is not legal, whether you enter 1--1000 or 1-- 10000,1234 is illegal.

However, this is not the same, the subject is intended requirement is less than F. (A) , and a is inputted, and dp array definition is: dp [pos] [sum], represents Currently pos position, prefixes, and for the sum of the answer,  such as assuming that the upper limit is 55555, then the answer is 123xxx and 321xxx dp [3] [6], which is the result of memory, because I do not need to consider the specific class in front of 123 or 321 114 number, as long as their and the same prefix and the sum of the same number of bits, where xxx is the same later, since the constraints are behind and not more than F (a) -sum.

The problem is in this place, because my memory of that is input and a F (a) relating to, so I can not use it as the nature of a number of words to remember, such as the same is 123xxx, for F (a) = 10 and F (a) = 20 is followed xxx is feasible, is not the same, a = 10, when the latter constraint is not greater than F (a) = -sum. 4 , a = 20 is the time constraint of no greater than F (a) -sum = 14 , each leading to a different input of a to be re-initialized dp array, re-search again. This can be done by defining a state of dp changes little, so that the constraints and becomes F (a) independent, thereby eliminating the need to re-initialize search each defined dp [pos] [SUM], represents the current at the pos bit, F (a) -sum answer ( SUM is the first to pos digit prefix bits and up), then at the pos position constraint is the number of all the rear and no greater than SUM , this time of the memory is SUM , is a F (a) unrelated , such as F (a) = 10 , andF (a) = 20 when, F. (A) = 10 when, 123xxx, 321xxx like corresponds dp [3] [. 4] , F (a) = 20 when, 556xxx, 466xxx corresponding also dp [3] [ 4] , since the two cases pos and F (a) -sum are the same, so that the memory of the once necessary to initialize

 

Guess you like

Origin www.cnblogs.com/wizarderror/p/11347119.html