Balanced Numbers (digit + shape pressure)

Source: Internet
Author: User

Test instructions: For a given interval, a number of digits on each odd number appear even several times, each even appears odd number of times, so that the number of

Analysis: First consider the state, but always think not, so to compress the state, with three, 0 the number does not put 1 odd number of times 2 put an even number of times

DP[I][J] The length of the I state is the number of J, requires a leading 0 judgement, leading 0 can not count the number of even occurrences.

#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007; ll dp[ -][100000],a,b;intbit[ -],cas[ the];
Three-Step systemvoid Get(intx) { for(intI=0; i<Ten; ++i) {cas[i]=x%3; X/=3; }}
State ChangeintChangeintXintb) { Get(x); if(cas[b]==0) Cas[b]=1; Else if(cas[b]==1) Cas[b]=2; Elsecas[b]=1; ints=0, tmp=1; for(intI=0; i<Ten; ++i) {s+=cas[i]*tmp; TMP*=3; } returns;}
To determine the qualifying conditionsintJudgeints) { Get(s); for(intI=0; i<Ten; ++i) {if(i%2&&cas[i]==1)return 0; if(i%2==0&&cas[i]==2)return 0; } return 1;} ll Dfs (intIintJintFinte) { if(i==0)returnjudge (J); if(!e&&dp[i][j]!=-1)returnDp[i][j]; intU=e?bit[i]:9; ll Num=0; for(intv=0; v<=u; ++v) {if(f&&v==0) Num+=dfs (I-1,0,1,e&& (v==u)); Else{num+=dfs (I-1, change (J,V),0,e&& (v==u)); } } if(!e) dp[i][j]=num; returnnum;} ll solve (ll x) {intlen=0; while(x) {bit[++len]=x%Ten; X/=Ten; } returnDFS (Len,0,1,1);}intMain () {intT; scanf ("%d",&t); Memset (DP,-1,sizeof(DP)); while(t--) {scanf ("%i64d%i64d",&a,&b); printf ("%i64d\n", solve (b)-solve (A-1)); } return 0;}

Balanced Numbers (digit + shape pressure)

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.