Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3652
Test instructions is the number of numbers that are divisible by 13 and contain "13" in an interval.
Definition Dp[len][mod][mark];
Where Len indicates the number of bits currently being processed or can be understood as the Len bit needs to be processed, the MoD represents the current total remainder (i.e. the remainder computed from the highest bit to the Len bit)
Mark plays the role of Mark
Mark==0 indicates that "13" has not appeared from the highest position to the I position;
The mak==1 indicates that "13" does not appear from the highest to the I bit, but the first bit is 1
mark==2 represents "13" from the highest bit to the I bit
Whether the flag flag has reached the upper limit
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <cstdio>6#include <vector>7#include <ctime>8#include <queue>9#include <list>Ten#include <Set> One#include <map> A using namespacestd; - #defineINF 0x3f3f3f3f -typedefLong LongLL; the - intbit[ the], dp[ the][ the][5]; - intDfs (intLenintMoDintMarkintflag) - { + intsum =0; - if(len = =0) + returnMoD = =0&& Mark = =2; A if(Flag && Dp[len][mod][mark] >=0) at returnDp[len][mod][mark]; - intTE = flag?9: Bit[len]; - for(inti =0; I <= te; i++) - { - intMoD = (mod *Ten+ i)% -; - intMark =Mark; in if(Mark! =2&& I! =1) -Mark =0; to if(Mark! =2&& i = =1) +Mark =1; - if(Mark = =1&& i = =3) theMark =2; *Sum + = Dfs (Len-1, Mod, Mark, flag | | I <te); $ }Panax Notoginseng if(flag) -Dp[len][mod][mark] =sum; the returnsum; + } A intMain () the { + intN; - while(~SCANF ("%d", &N)) $ { $memset (bit,0,sizeof(bit)); - intLen =0; - while(n) the { -Bit[++len] = n%Ten;WuyiN/=Ten; the } -Memset (DP,-1,sizeofDP); Wucout<< Dfs (Len,0,0,0) <<Endl; - } About return 0; $}
View Code
HDU3652_ Digital DP