4521: [Cqoi2016] Mobile number time limit:10 Sec Memory limit:512 MB
submit:539 solved:325
[Submit] [Status] [Discuss] Description people to choose mobile phone number when the number is good to remember, auspicious. For example, the number contains several adjacent to the same number, does not contain homophonic unlucky numbers. These factors are also taken into account by mobile operators when issuing new numbers, which are sold separately from numbers that contain certain features. To facilitate early planning, operators want to develop a tool to automate the number of numbers in a number segment that satisfies a feature. Tool needs to detect the number characteristics of two: the number to appear at least 3 adjacent to the same number, the number can not appear at the same time 8 and 4. The number must contain two characters to satisfy the condition. The number that satisfies the condition, such as 13000988721, 23333333333, 14444101000. The numbers that do not meet the criteria are for example: 1015400080, 10010012022. Mobile phone number must be 11 digits, the front does not contain the leading 0. The tool receives two numbers L and R and automatically counts the number of all the numbers in the [L,r] range that meet the criteria. L and R are also 11-bit mobile numbers. Input file content is only one row, 2 positive integer l, R, separated by a space. 10^10 < = L < = R < 10^11output
The output file contains only one row, 1 integers, indicating the number of mobile numbers that meet the criteria.
Sample Input12121284000 12121285550Sample Output5
Sample explanation
The number that satisfies the condition: 12121285000, 12121285111, 12121285222, 12121285333, 12121285550Hintsourcesolution
This is a simple digital DP, the state is not difficult to think: F[i][j][k1][k2][k3][k4][k5].
Means to do the first bit, put the number of J, whether the last two consecutive digits are the same, whether there are three consecutive bits of the same, whether there are 4, whether there is 8, the prefix and the prefix is the same as the original number.
The transfer is also relatively simple, enumerate the above things, and then enumerate the i+1 bit of what to fill, according to test instructions transfer can be.
However, it should be noted that the initialization of the time needed to get a 10th place out, or the two consecutive will be sentenced to be more injured.
and generally it is Cal (R)-cal (L-1), if the fixed 11-bit to do the problem will occur, this time can be used to open the interval to do, become Cal (r+1)-cal (L).
Code
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <string>5#include <algorithm>6 7 using namespacestd;8 9 #defineFIO "a"Ten #defineREP (I, A, b) for (int i = (a), i# #_end_ = (b); I <= i# #_end_; ++i) One #defineMset (A, B) memset (A, B, sizeof (a)) A Const intMAXN = the; -typedefLong LongLL; -LL f[maxn][maxn][2][2][2][2][2], L, R; the //x?μ?μúi?? £?x????? Ê?j£?x?oóá??? êyê?? á? d?£?ê?? Ódá? D?èy??? àí?£?ê?? ód4£?ê?? Ód8£?? °xoó?? -êy?°xoμ?1?? μ - - ll Cal (ll x) - { +Mset (F,0); -LL ans =0;intLen =0, digit[ the], A, B, C, D, E; + while(x) {Digit[++len] = x percentTen, x/=Ten; } AReverse (digit+1, digit+len+1); atf[0][Ten][0][0][0][0][1] =1; -REP (I,0, len-1) -REP (J,0,Ten) -REP (K1,0,1) -REP (K2,0,1) -REP (K3,0,1) inREP (K4,0,1) -REP (K5,0,1) to if(F[i][j][k1][k2][k3][k4][k5]) +REP (k,0,9) - { the if(K5 && k > digit[i+1])Continue ; * if(k = = j) A =1;ElseA =0; $ if(!K2) b = (A+k1 = =2);Elseb =K2;Panax Notoginseng if(!K3) c = (k = =4);Elsec =K3; - if(!K4) d = (k = =8);ElseD =K4; the if(C+d = =2)Continue ; + if(K5 && k = = digit[i+1]) E =1;ElseE =0; Af[i+1][k][a][b][c][d][e] + =F[I][J][K1][K2][K3][K4][K5]; the } +REP (J,0,9) -REP (K1,0,1) $REP (K3,0,1) $REP (K4,0,1) - { - if(K3 && K4)Continue ; theAns + = f[len][j][k1][1][k3][k4][0]; - }Wuyi returnans; the } - Wu intMain () - { About //freopen (FIO ". In", "R", stdin); $ //freopen (FIO ". Out", "w", stdout); -scanf"%lld%lld", &l, &R); -printf"%lld\n", Cal (r+1)-cal (L)); - return 0; A}View Code
Bzoj 4521 Cqoi 2016 mobile phone number DP