Number of topics digit DP P2657 [SCOI2009] windy number P4317 flora of P4124 [CQOI2016] phone number

Digital DP

Digital dp
classic digital Dp is in line with the statistical requirements limit the number of digits.
The general form is: find the interval [n, m] satisfy the constraints F (. 1) , F  (2) , F  (. 3) so the number of digits is
the number. Conditions  f (i)  generally independent of the magnitude of the number, and the number of constituent concerned.
make good use of different band to deal with general problems are 10 hex and binary digits dp .
digit dp parts are generally very routine, but some topics in digital dp outside the set of a
gorgeous coat, sometimes we can not see it. 

 

 

> HDU3652
statistical interval  [1, n]  contains  '13'  and the die  13  is  digits how many.
◦  N <= 10 ^. 9 

>Solution

139915366 991 366 containing free

HDU3652 simplified version
to enumerate violence every number and then to calculate the inevitable slow.
us first consider a simpler form
statistical interval  [1, n]  contains  '3'  figures of how many. 

 

◦  N x_1 = x_2 X_3 X_total X_4 ... ..  x_i is n descending of the i is the number of bits. Total is the total
number of bits.
◦  If we continue to fill the number of bits in descending consider Y_1 y_2 ... . So the question really is to ask how
the program fill a small number, one must meet the cap limit (corresponding to the interval [1, the n-] ), two to meet the subject
to other restrictions.
◦  this fact than [1, n] looks more dp up. 

assumed that the first k bits Y_k! = X_k , then k is no upper limit on the bit after, the situation is simplified.
If the previous y does not appear in 3 : So if we can find out,  f [k] [0] represents the k did after the position
has an upper limit (free to fill in), but must fill in a 3 (front does not appear), how many fill
program numbers.
If the front y appeared in 3 so if we can find out,:  f [k] [1] represents the k no after-bit
upper limit (free to fill), did not have to appear 3 restrictions (front appeared a) how many
the number of species fill program. 

 

First, we can enumerate where a Y_k! = X_k , then this one is the number of enumeration, the correspondence
of F together is the answer, and a total need to increase  the number of bits * 10  times. This is a small number of operations.
and f array total size is small,  the number of bits * 2 .

boundary  F [Total +. 1] [0] = 0, F [Total +. 1] [. 1] =. 1 , the transfer complexity of O (10)
overall complexity 

 

then return to the original title of it?
Which different enumeration nothing changes it, as with the original enumeration enough.
is f array to be changed, because more constraints, so the dimension of the state is to be increased.
set f [k] [ earlier whether there have been 13] [ on whether one is 1] [ those in front of the number mod13 equivalent to more
less ], then transfer the same or enumerate what this one can fill. 

 


> That these are not what we would have done it!
write equations stroked his thoughts.
◦  1 : statistical interval  [m, n]  in the 4 and 7 figures can not appear at the same time how many?
◦  2 : give you an interval [n, m], to ask you free interval "62" or "4" number of digits of?
◦  3 bzoj1026 windy defines a windy number. Without leading zeros , and the adjacent two numbers
differing by at least two positive integers it is called windy number. windy want to know, in A and B between the packet
including A and B , a total number of windynumber? 

> Memory search to achieve
In fact, we have just the dp of the natural process of thinking is very clear, but generally we do not realize
that writing. Because, after all, a good number for the cycle, pre-set cycle, a cycle count answer
ring, remember the words search, then what is what to count, write a lot of good will.
In fact digit dp are often used way to achieve search memory, is seeking what to call what
it is called over, down , next time do not forget again.
we look at the code on a theme 

◦   represents the first of several.
◦  State : whether on a 1 .
◦  Have: whether there are 13. The
◦  K : The number has been added mod13 value
attention not only to the top of the upper bound of memory down to answer. 


 

About Digital dp experience
◦  1 : Note Many times we bring in is n == 0 for special treatment.
◦  2 : There usually ask [m, the n-] , we find [1, n] - [1 , m-1] but sometimes m is 0 to explode. Then
after a question wa an hour. . . . . . normal. . . . .
◦  3 : require that all contain 49 numbers, in fact, (total - do not contain 49 numbers). The former of the
need to have two-dimensional limitations, one on one is what one is there before 49 . But after
only need to remember what a on a yes. I can write some good.
◦  4 : Digital general questions dp part, are routine, but this does not mean out of it "gorgeous
coat" and part combined with other algorithms is no brain. To see it is to test digital dp ,
to see what is the problem of how changes in digitaldp up.

◦  . 5 DP initialization memset be set to -1 . Can not be set to 0 ! ! ! ! ! ! Because there are times when
dp value should be 0 , then we are mistaken because if not calculated before, the new calculations
, it would TLE .

there can not be written as 0 .
◦  6 : Since it is the memory of the search, it can be pruned! ! ! ! Feasibility pruning! !
◦  7 : Note windy when the number of, sometimes leading 0 also need to remember! !

 

> Hdu3079
number of the title is defined in the balance: a position as to balance shafts, and other digital itself around large
small as weight, as the distance to the weight of the balance shaft, to achieve the left and right balance (i.e., lever principle level
balance). Then to the interval [x, y] number of the number of equilibrium. (0 ≤ X ≤ 10 Y ≤ 18 is

>Solution

digit dp course and a variety of algorithms can be set up.
This is a typical problem of enumeration + digital dp

First of all, I feel this question if the current record position, the election did not choose balance shafts, the current balance of the left pole right
value minus the weight balance bar to the right, so that does not feel good transfer. The analysis of the nature of the topic can be found,
a non- 0 number can only have a (one to one) the balance shaft ( 0 except for a final special treatment
under the like), then if the number of bits dp outside the enumeration balance shaft, then just calculate in the end the difference is
whether to 0 just fine. Since the central axis of each corresponding set of mutually exclusive legal
Note 0 special case: that is, 0 is counted several bits, can be lost.

 

example:

>P2657 [SCOI2009]windy数

 

> Number of topics P4317 Flora ( bzoj3209 )

 

> P4124 [CQOI2016] phone number ( bzoj4521 )

 

 

to sum up

 

Guess you like

Origin www.cnblogs.com/xiaoyezi-wink/p/11468568.html