Bzoj_1833_[zjoi2010]_ Digit Count _ (digital DP)

Source: Internet
Author: User

Describe

http://www.lydsy.com/JudgeOnline/problem.php?id=1833

Statistics \ (a~b\) in number \ (0,1,2,..., 9\) how many times respectively.

Analysis

Digital DP is really the details and more error-prone, I do not bother to read the problem, so also lazy to write the problem ...

Pay attention to the details, or ...

1#include <bits/stdc++.h>2 using namespacestd;3 4typedefLong Longll;5 ll A, B;6ll a[Ten],b[Ten],num[ the];7ll f[ -][Ten][Ten];8 9 voidSolve (ll X,ll *a) {Ten     if(x==0)return; One     if(x<Ten){ A          for(intI=1; i<=x;i++) a[i]=1; -         return; -     } the     intCnt=0; -ll t=0; -      while(x) num[++cnt]=x%Ten, x/=Ten; -      for(intI=1; i<cnt;i++) for(intj=1; j<=9; j + +) for(intk=0; k<=9; k++) a[k]+=F[i][j][k]; +      for(intI=1; i<cnt;i++){ -          for(intj=0; j<num[i];j++) for(intk=0; k<=9; k++) a[k]+=F[i][j][k]; +a[num[i]]+=t+1; t=t+num[i]* (LL) POW (Ten, I-1); A     } at      for(intj=1; j<num[cnt];j++) for(intk=0; k<=9; k++) a[k]+=F[cnt][j][k]; -a[num[cnt]]+=t+1; - } - intMain () { -scanf"%lld%lld",&a,&b); -      for(intI=0; i<=9; i++) f[1][i][i]=1; in      for(intI=2; i<= -; i++){ -          for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) f[i][0][k]+=f[i-1][j][k]; to          for(intj=1; j<=9; j + +) for(intk=0; k<=9; k++) f[i][j][k]=f[i][0][k]; +          for(intj=0; j<=9; j + +) f[i][j][j]+= (ll) POW (Ten, I-1); -     } theSolve (B,B); Solve (A-1, A); *      for(intk=0;k<9; k++) printf ("%lld", b[k]-a[k]); $printf"%lld\n", b[9]-a[9]);Panax Notoginseng     return 0; -}
View Code

1833: [Zjoi2010]count Digital Count time limit:3 Sec Memory limit:64 MB
submit:2569 solved:1132
[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

Bzoj_1833_[zjoi2010]_ Digit Count _ (digital 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.