"BZOJ-1833" count number of digits DP

Source: Internet
Author: User

1833: [Zjoi2010]count Digital Count time limit:3 Sec Memory limit:64 MB
submit:2494 solved:1101
[Submit] [Status] [Discuss] Description given two positive integers a and B, for all integers in [a, b], how many times each digital (digit) appears. Only one line of two integers a, B, is included in the input file, meaning as described above. The output file contains a row of 10 integers representing the number of times that 0-9 appears in [A, b]. Sample Input1 99
Sample Output9 20 20 20 20 20 20 20 20 20
HINT

30% of the data in,a<=b<=10^6;
100% of the data, a<=b<=10^12.

Source

Day1

Solution

Bare digital DP But it's actually not special water

First F[i][j][k] indicates the number of K-numbers with a maximum number of bits as J

Split by decimal, post-processing statistical answer

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Long LongL,r;Long Longf[ the][Ten][Ten],ans1[Ten],ans2[Ten]; voidprework () { for(intI=0; i<=9; i++) f[1][i][i]=1; Long Longtmp=1;  for(intI=2; i<= A; i++) {tmp*=Ten; f[i][0][0]=f[i-1][1][0]*9+f[i-1][0][0]+tmp;  for(intj=1; j<=9; J + +) f[i][0][j]=f[i-1][0][j]*9+f[i-1][j][j];  for(intj=1; j<=9; J + +) {f[i][j][0]=f[i-1][1][0]*9+f[i-1][0][0];  for(intk=1; k<=9; k++)                         if(j==k) F[i][j][k]=f[i-1][0][k]*9+f[i-1][k][k]+tmp; ElseF[i][j][k]=f[i-1][0][k]*9+f[i-1][k][k]; }         } } Long LongCfintx) {Long LongRe=1;  for(intI=1; i<x; i++) Re*=Ten; returnre;} voidCalc (Long LongXLong Long*ans) {     intdigit[ the]={0},len=0;Long Longy=x;  while(x) {digit[++len]=x%Ten; X/=Ten;}  for(intI=1; i<len; i++)          for(intj=1; j<=9; J + +)              for(intk=0; k<=9; k++) Ans[k]+=F[i][j][k];  for(intI=len; i>=1; i--)         {              for(intj=0; j<=digit[i]-1; J + +)                 {                     if(I==len && j==0)Continue;  for(intk=0; k<=9; k++) ans[k]+=F[i][j][k]; } Ans[digit[i]]+=Y%CF (i) +1; } } intMain () {prework (); scanf ("%lld%lld",&l,&s); Calc (L-1, ans1);     Calc (R,ANS2); printf ("%lld", ans2[0]-ans1[0]);  for(intI=1; i<=9; i++) printf ("%lld", ans2[i]-Ans1[i]); return 0; }

Oneself at the beginning of yy error.

"BZOJ-1833" count count number of digits DP

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.