Bzoj 1833 Zjoi count number of digits DP

Source: Internet
Author: User

Question: Ask 0~9 how many times these 10 numbers appear in [L,r].


IDEA: Digital DP. Previously just heard, and did not write, wrote to find a good upset AH.

Preprocessing an array, F[i][j][k] represents the length of I, starting with J, the number of times that the numbers K appears.

For a number kxxxxxx, we deal with 1~999999 first, and then we deal with 1000000~KXXXXXX

The front is very regular, you can directly call the F array to solve.

For things that are not very regular at the back, bitwise processing. In a word, I don't know what to say or do.


CODE:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;long long F[15][10][10],power[15];long long a[10],b[10];void work (long long X,long long arr[]) {Long Long temp = X;int  len = 0;static int Digit[15];memset (digit,0,sizeof (digit)), while (x) digit[++len] = x% 10,x/= 10;x = temp;for (int i = 1; i < Len;  ++i) for (int j = 1; J <= 9, ++j) for (int k = 0; k <= 9; ++k) arr[k] + = f[i][j][k];for (int i = len; i; i) {for (int j = 0; J < Digit[i]; ++J) {if (!j && i = = len) continue;for (int k = 0; k <= 9; ++k) arr[k] + = F[i][j][k];} Arr[digit[i]] + = x% power[i] + 1;}} int main () {power[1] = 1;for (int i = 2; I <=; ++i) power[i] = power[i-1] * 10;for (int i = 0; I <= 9; ++i) f[1][i][  I] = 1;for (int i = 2; I <=; ++i) for (int j = 0, J <= 9; ++j) for (int k = 0, K <= 9; ++k) {for (int z = 0; z <= 9; ++Z) f[i][k][z] + = F[i-1][j][z];f[i][k][k] + + power[i-1];} Long Long l,r;scanf ("%lld%lld", &l,&r); Work(R,a), work (l-1,b); for (int i = 0; I <= 9; ++i) printf ("%lld%c", A[i]-b[i], "\ n" [i = = 9]); return 0;} 


Bzoj 1833 Zjoi 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.