Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=1026
Very basic digital DP problem, I tried to do this problem very early, but I was frightened by this problem, now back to do this problem, feel much simpler.
To do this problem, I think of POJ a similar combination of mathematical problems, the same is the number of statistics, there are similarities.
The title requires a number of windy on the [a, b] interval, and we can convert the number of windy on the [1,a] windy number of-[1,b-1]. The title turns into a number of windy on [1,x], and we write a function cal (x). In addition we use w[i][j] to denote a number of length I, the highest bit is J ( Note J can be 0) composed of windy number. It is easy to deduce the formula w[i][j]=σw[i-1][k],0<=k<=9,|k-j|>=2. After the problem has been dealt with, it is a matter of bitwise statistics. (1) First we count the number of windy of the length is less than x, (2) and then the length is equal to X, the highest digit is less than the highest digit of x windy number of digits, (3) and then from the second high to the single bit by the same steps (2) of the method statistics. In order to avoid the case of leading zeros, w[i][0] cannot be counted in the highest bit statistics.
Many people on the internet from low to high method of statistics, too complex, but also to discuss, really better from high to low statistics come convenient, embarrassing.
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < Algorithm> #define INF 0x3f3f3f3fusing namespace std;typedef long Long int ll;int primes[]={0, 2, 3, 5, 7, 11, 13, 17, 1 9, 23, 29}; Prime number to play table ll n,ans,cnt; Cnt= approximately the number of maximum values, ans= the smallest number when the maximum is about several numbers void DFS (LL num,ll maxp,int now,int nowcnt)//num= the number obtained by the current product, maxp= the largest power of the next prime number, now= The prime number subscript used in the current state, nowcnt= the current count { if (nowcnt>cnt| | Nowcnt==cnt&&num<ans) { cnt=nowcnt; Ans=num; } if (now>10) return; Take the number of mass number too many, has exceeded the range of N, do not have to continue to search for LL nownum=num; for (int i=1;i<=maxp;i++)//Enumerate the power of the next factorization { nownum*= (LL) Primes[now]; if (nownum>n) return; DFS (nownum,i,now+1,nowcnt* (i+1));} } int main () { scanf ("%lld", &n); Ans=1,cnt=1; DFS (1,inf,1,1); printf ("%lld\n", ans); return 0;}
[Bzoj 1026] [Scoi 2009]windy number (digital DP)