[Bzoj 1833] [ZJOI2010] Count number count "digital DP"

Source: Internet
Author: User

Title Link: BZOJ-1833

Problem analysis

Digital DP..

Using F[i][j][k] Indicates the number of digits K for the i digit of J.

Then differential inquiry ... Get () Note that if the bit I is fixed, this is T, then the answer to the digital T is to add a value (see Code).

Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <algorithm>using namespace std;const int maxbit = 15;typedef long long ll;struct es{ll a[11];}; ES operator + (const es &a, const es &b) {ES ret;for (int i = 0; I <= 9; ++i) ret. A[i] = A.a[i] + b.a[i];return ret;} LL A, B; LL P10[maxbit]; Es f[maxbit][11];es Get (LL x) {ES ret;for (int i = 0; I <= 9; ++i) ret. A[i] = 0;if (x = = 0) return ret;int L = 1;while (P10[l] <= x) ++l;for (int i = 1; I <= l-1; ++i) {for (int j = 1; J <= 9; ++J) {ret = ret + f[i][j];}} 0 were not counted ++ret. A[0]; LL T; t = x/p10[l-1];x%= p10[l-1];//If there is only 1 bits, the following will not be counted 0, but already on the above 0 for (int i = 1; I <= t-1; ++i) ret = ret + f[l][i] ; ret. A[t] + = x;for (int i = L-1; I >= 1; i.) {t = x/p10[i-1];x%= p10[i-1];for (int j = 0; J <= t-1; ++j) ret = ret + F[i][j];ret. A[T] + = x;} return ret;} int main () {p10[0] = 1LL; for (int i = 1; i <=; ++i) P10[i] = P10[I-1] * 10ll;for (int i = 1; i <=; ++i) {for (int j = 0; J <= 9; ++j) {for (int k = 0; k <= 9; ++k) {F[i ][J] = F[i][j] + f[i-1][k];} F[I][J]. A[J] + = P10[i-1];}} scanf ("%lld%lld", &a, &b); ES TA, Tb;ta = Get (A); TB = Get (B + 1), for (int i = 0; I <= 9; ++i) {printf ("%lld", TB. A[i]-TA. A[i]); if (i = = 9) printf ("\ n"), Else printf ("");} return 0;}

  

[Bzoj 1833] [ZJOI2010] Count number 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.