"BZOJ-4521" Mobile number DP

Source: Internet
Author: User

4521: [Cqoi2016] Mobile number time limit:10 Sec Memory limit:512 MB
submit:303 solved:194
[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 data range, one-eye digital DP, but not particularly good to engage ...

F[I][J][0/1][0/1][0/1][0/1][0/1] indicates that the number of bits is I, the highest bit is J, the maximum number of consecutive two is the same, whether there are 3 consecutive same, whether there is 4, whether there is 8, prefix and the size of the prefix prefixes relationship

Enumerate these things .... K1,K2,K3,K4,K5, respectively, that corresponds to the above 0/1

Note & Inspire:

1. Digital DP generally take preprocessing, after summing, where the data range of direct processing is very convenient, using direct processing

2. Note that the scope $l<=10^{10}$ default 10-bit does not directly calculate the Calc (R)-calc (L-1), here can be discussed, or the processing interval is open interval, calculate Calc (r+1)-calc (L) can be

3. Note the enumeration of state, some fragmentary judgments need to be cleared, otherwise you will fall into the mire (WA countless, overwhelmed)

4. If digit[] is more convenient to consider the positive sequence processing, plus this problem can take a special enumeration method

5. A deeper understanding of the digital DP, but still need more practice, overall, the problem is a good topic, you can think of is only the framework, the implementation is still a bit wrong

Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Long Longf[ -][ the][2][2][2][2][2],l,r;intp[ -],num;Long LongCalLong Longx) {memset (F,0,sizeof(F)); Long Longans=0;intlen=0, digit[ A],a,b,c,d,e;  while(x) {digit[++len]=x%Ten; X/=Ten;} Reverse (Digit+1, digit+len+1); f[0][Ten][0][0][0][0][1]=1;  for(intI=0; i<=len-1; i++)         for(intj=0; j<=Ten; J + +)             for(intk1=0; k1<=1; k1++)                 for(intK2=0; k2<=1; k2++)                     for(intk3=0; k3<=1; k3++)                         for(intk4=0; k4<=1; k4++)                             for(intk5=0; k5<=1; k5++)                                if(F[i][j][k1][k2][k3][k4]) for(intk=0; k<=9; k++)                                        {                                            if(K5 && (k>digit[i+1]))Continue; if(K==J) a=1;ElseA=0; if(k2==0) b= (k1+a) = =2;Elseb=K2; if(k3==0) c= (k==4);ElseC=K3; if(k4==0) d= (k==8);ElseD=K4; if((c+d) = =2)Continue; if(K5 && (k==digit[i+1])) e=1;ElseE=0; F[i+1][k][a][b][c][d][e]+=F[I][J][K1][K2][K3][K4][K5]; }     for(intI=0; i<=9; i++)         for(intk1=0; k1<=1; k1++)             for(intk3=0; k3<=1; k3++)                 for(intk4=0; (k4<=1) && (k4+k3<2); k4++) ans+=f[len][i][k1][1][k3][k4][0]; returnans;}intMain () {scanf ("%lld%lld",&l,&R); printf ("%lld\n", Cal (r+1)-cal (L)); return 0;}

Last night wrote the number (s) bit (W) DP, resulting in the second day of the semester math (s) Physics (W) Metrorrhagia ... Although 1 months of class, on the 1/4 less than ... But I'm upset, o_o.

"BZOJ-4521" Mobile number DP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.