bzoj1833 [Zjoi2010]count Digit Count

Source: Internet
Author: User

Topic links

I am the DP weak!!! I am the DP weak!!! I am the DP weak!!!

Adjusted for a long time, digital DP good annoyed Qaq

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <string>7#include <cmath>8#include <ctime>9#include <queue>Ten#include <stack> One#include <map> A#include <Set> - #defineRre (i,r,l) for (int i= (r); i>= (l); i--) - #defineRe (I,L,R) for (int i= (l); i<= (R); i++) the #defineClear (A, B) memset (A,b,sizeof (a)) - #defineInOut (x) printf ("%d", (x)) - #defineDouin (x) scanf ("%lf", &x) - #defineStrin (x) scanf ("%s", (x)) + #defineLLin (x) scanf ("%lld", &x) - #defineOP operator + #defineCSC Main Atypedef unsignedLong LongULL; attypedefConst intCInt; -typedefLong LongLL; - using namespacestd; - voidInin (int&ret) - { -ret=0;intf=0;CharCh=GetChar (); in      while(ch<'0'|| Ch>'9'){if(ch=='-') f=1; ch=GetChar ();} -      while(ch>='0'&&ch<='9') ret*=Ten, ret+=ch-'0', ch=GetChar (); toret=f?-Ret:ret; + } -LL ten[ -]; theLL dp[ -][Ten][Ten]; * voidGetpre () $ {Panax Notoginsengten[0]=1; -Re (I,1, A) ten[i]=ten[i-1]*Ten; theRe (I,0,9) dp[1][i][i]=1; +Re (I,2, A) Re (J,0,9) Re (k,0,9) A     { thedp[i][j][k]= (j==k)? ten[i-1]:0; +Re (t,0,9) dp[i][j][k]+=dp[i-1][t][k]; -     } $ } $ intgetbit (LL x) - { -     intret=0; the      while(x) -X/=Ten, ret++;Wuyi     returnret; the } -LL ans[Ten]; Wu intnum[ the]; - voidCalc (LL Temp,intBitBOOLQian) About { $     if(!bit)return; -     if(Qian) -Re (I,0, num[bit]-1) -Re (J,0,9) Aans[j]+=Dp[bit][i][j]; +     ElseRe (I,1, num[bit]-1) Re (J,0,9) ans[j]+=Dp[bit][i][j]; theans[num[bit]]+=temp%ten[bit-1]+1; -Calc (temp,bit-1,1); $ } the voidCALC2 (LL temp,intBitBOOLQian) the { the     if(!bit)return; the     if(Qian) -Re (I,0, num[bit]-1) inRe (J,0,9) theans[j]-=Dp[bit][i][j]; the     ElseRe (I,1, num[bit]-1) Re (J,0,9) ans[j]-=Dp[bit][i][j]; Aboutans[num[bit]]-=temp%ten[bit-1]+1; theCALC2 (temp,bit-1,1); the } the intMain () + { - Getpre (); the LL l,r;Bayiscanf"%lld%lld",&l,&R); the     intlen=0; theLL temp=R; -      while(r) num[++len]=r%Ten, r/=Ten; -Calc (Temp,len,0); theRe (I,1, len-1) Re (J,0,9) Re (k,1,9) ans[j]+=Dp[i][k][j]; thelen=0, temp=l-1; l--; the      while(l) num[++len]=l%Ten, l/=Ten; theCALC2 (Temp,len,0); -Re (I,1, len-1) Re (J,0,9) Re (k,1,9) ans[j]-=Dp[i][k][j]; theRe (I,0,9) printf ("%lld%c", ans[i],i==9?'\ n':' '); the      return 0; the}

bzoj1833 [Zjoi2010]count Digit Count

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.