Bzoj4521 [Cqoi2016] Mobile phone number

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:512 MB
submit:557 solved:335 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, 12121285550

Dynamic Programming Digital DP

Very simple digital DP. I still remember how the number of DP how to write, really touched.

The 30th line reset lines (number of consecutive numbers) should be reset to 1, hit 0 half a day not to see

There is a pit point: when L is 10000000000, -1 Calc () will go wrong.

↑ I should not be able to get stuck with the DFS notation, but I set up a St in line 25 in order to solve the leading 0 problem.

Just a special.

1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <cmath>6#include <vector>7 #defineLL Long Long8 using namespacestd;9 Const intmxn= -;Ten intdig[mxn],len=0; OneLL f[mxn][mxn][mxn][2][2][2][2]; ALL DFS (intNowintLastintLineBOOLHaBOOLYoBOOLMiBOOLflag) { -     //Current position previous number of consecutive numbers 8 43 upper bound -     if(!flag && f[now][last][line][ha][yo][mi][flag]!=-1)returnF[now][last][line][ha][yo][mi][flag]; the     if(Ha&yo)return 0; - //printf ("now:%d last:%d line:%d%d%d%d\n", now,last,line,ha,yo,mi); -     if(!Now ) { -         if(MI)return 1; +         return 0; -     } +LL &dp=F[now][last][line][ha][yo][mi][flag]; ALL res=0; at     intLim=flag?dig[now]:9; -     intSt; -     if(Now==len) st=1;Elsest=0; -      for(inti=st;i<=lim;i++){ -         BOOLnflag=flag& (i==Lim); -         BOOLnha=ha| (i==8); in         BOOLnyo=yo| (i==4); -         intNline= (i==last)? line+1:1; to         BOOLnmi=mi| (nline>=3?1:0); +Res+=dfs (now-1, I,nline,nha,nyo,nmi,nflag); -     } thedp=Res; *     returnRes; $ }Panax Notoginseng ll Calc (ll x) { - //memset (f,-1,sizeof f); thelen=0; +      while(x) { Adig[++len]=x%Ten; theX/=Ten; +     } -     returnDFS (len,-1,0,0,0,0,1); $ } $ LL l,r; - intMain () { -     inti,j; thescanf"%lld%lld",&l,&R); -memset (f,-1,sizeoff);WuyiLL ans=0; the     if(l==10000000000) ans=Calc (R); -     ElseAns=calc (R)-calc (l1); Wuprintf"%lld\n", ans); -     return 0; About}

Bzoj4521 [Cqoi2016] Mobile phone number

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.