Description
When people choose their mobile phone number, they want the number to be good and auspicious. For example, the number contains several adjacent the same number, does not contain homophonic
Geely's numbers and so on. Mobile operators will also consider these factors when issuing new numbers, and select numbers with certain features from the segment.
Yards sold separately. To facilitate early planning, operators want to develop a tool to automatically count the number of numbers in a number segment that satisfies a feature
Amount
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 be the same
When 8 and 4 are present. The number must contain two characters to satisfy the condition. The number that satisfies the condition, for example: 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. Tool receives two numbers L and R, automatically counts [l,r] Intervals
The number of all the numbers in the condition that meet the criteria. L and R are also 11-bit mobile numbers.
Input
Input file content is only one line, 2 positive integer l, R, separated by a space.
10^10 < = L < = R < 10^11
Output
The output file contains only one row, 1 integers, indicating the number of mobile numbers that meet the criteria.
Sample Input
12121284000 12121285550
Sample Output
5
Sample explanation
Numbers that meet the criteria: 12121285000, 12121285111, 12121285222, 12121285333, 12121285550
Exercises
Digital DP, which in turn determines each bit. Set state \ (f[i][j][0/1][0/1][0/1][0/1][0/1]\) indicates that the front \ (i\) bit is determined, and that the first \ (i\) bit is \ (j\), The last two bits are the same, whether there are three identical numbers adjacent, whether there is a \ ( 4\), whether there is a \ (8\), whether the currently determined bit is up to the upper bound of the number of satisfied conditions.
Then write a eight-cycle, enumerate the seven values and the number of \ (i+1\) bits filled, updating the new state.
Exercises
#include <bits/stdc++.h>#define LL Long Long#define UP (x, Y, z) for (int x=y;x<=z;x++)using namespaceStd LL f[ the][ A][2][2][2][2][2],l,r;//Currently processed I bit is the same as J last two bit//Whether there are three consecutive same numbers whether there are 4 whether there are 8 prefixes reaching the upper limitintp[ the],cnt,a,b,c,d,e; ll Calc (ll x) {//Open ZoneMemset (F,0,sizeof(f)); LL t=x,ans=0; cnt=0; while(t) {p[++cnt]=t%Ten; t/=Ten;} Reverse (P+1P+1+CNT); f[0][Ten][0][0][0][0][1]=1; Up (I,0Cnt-1) Up (J,0,Ten) Up (K1,0,1) Up (K2,0,1) Up (K3,0,1) Up (K4,0,1) Up (K5,0,1)if(F[i][j][k1][k2][k3][k4][k5]) up (K,0,9){if(K5&&k>p[i+1])Continue; A= (K==J); B=k2? K2: ((a+k1) = =2); C=k3? k3:k==4; D=k4? k4:k==8;if(c&d)Continue; E= (k5&&k==p[i+1]); F[i+1][K][A][B][C][D][E]+=F[I][J][K1][K2][K3][K4][K5]; } Up (I,0,9) Up (K1,0,1) Up (K3,0,1) Up (K4,0,1){if(K3&K4)Continue; ans+=f[cnt][i][k1][1][k3][k4][0]; }returnAns;}intMain () {#ifndef Online_judgeFreopen ("Bzoj4521.in","R", stdin); Freopen ("Bzoj4521.out","W", stdout);#endifscanf"%lld%lld", &l,&r); printf"%lld", Calc (R+1)-calc (l));return 0; }
bzoj4521: [Cqoi2016] Mobile phone number