← 返回 google 的题目列表Count Perfect Wake Numbers ≤ N (Digit DP)
类型:online_judge
Count Perfect Wake Numbers in [1, N]
A positive integer is called a Perfect Wake Number iff it satisfies all of the following:
Its decimal representation does not contain digit 0.
No digits are repeated.
No digit is adjacent to two strictly larger digits.
Formally, for digit array d[1..L], it is not allowed to have an index i with 1 < i < L such that d[i-1] > d[i] and d[i+1] > d[i].
Given an integer N (1 ≤ N ≤ 10^18), return how many integers in [1, N] are Perfect Wake Numbers.
Examples
196, 23, and 12463 are Perfect Wake Numbers.
1546 is not (digit 4 has neighbors 5 and 6, both larger).
320 is not (contains 0).
34321 is not (repeats digit 3).
Example
Input
1
Output
1