[LuoguP4124] [CQOI2016] phone number

Title Description

When people want to select the phone number easy to remember number, auspicious. Such numbers contain the same number of several adjacent, free of harmonics unlucky number and the like. Mobile phone operators when issuing new number will also consider these factors, we choose the numbers contain some features from the medium segment sold separately. In order to facilitate pre-planning, operators hope to develop a tool to automatically count the number of numbers to meet the characteristics of the segment number.

Wherein the number of tools necessary to detect two: numbers to appear in at least  three adjacent identical numbers; can not both numbers  8 and  4. Characterized in comprising two numbers must satisfy a condition. Meet the conditions of numbers such as: 13000988721,23333333333,14444101000. Does not satisfy the conditions of example number: 1015400080,10010012022.

Phone number must be  1 digit, without preamble before  0. Tool receiving two numbers  L  and  R, an automatic statistics  [L, R]  number satisfying the condition number of all within the interval. L  and  R are  . 1 a mobile phone number.

Input Format

Only the contents of the input file a line, a space-separated  2  positive integers  L, R & lt .

Output Format

Output file content only one line for  1  integer representing the number of phone numbers that satisfy the condition.

Sample input and output

Input # 1
12121284000 12121285550
Output # 1
5

Description / Tips

Sample explained: Number meet conditions: 12121285000, 12121285111, 12121285222, 12121285333, 12121285550.

data range:

  10^10 <= L,R <= 10^11

Ideas:

    This is a digital DP

Code:



	if( dp[p][a][b][c][d][pan4][pan8] !=-1) return dp[p][a][b][c][d][pan4][pan8];
	for(int i=0;i<=lim;i++)
	{
		res+=f( p-1 , i , a , c||(i==b&&i==a) , d||(i<lim) ,pan4||(i==4),pan8||(i==8));
	}
	return dp[p][a][b][c][d][pan4][pan8] = res;
}
int calc(int x)
{
	if(x < 1e10)return 0;
	memset(dp ,-1 , sizeof( dp ) );
	for(len=0 ; x; x/=10) num[++len] = x%10;
	int res = 0;
	for ( int i = 1;i <= num[len]; i++)
	{
		res+=f(10,i,0,0,i<num[len],i==4,i==8);
	}
	return res;
}
signed main()
{
	l = read();
	r = read();
	printf("%lld", calc(r) - calc(l-1) );
	return 0;
}

  

 

Guess you like

Origin www.cnblogs.com/yelir/p/11535978.html