HDU2089 (Digital DP), hdu2089 digital dp

Source: Internet
Author: User

HDU2089 (Digital DP), hdu2089 digital dp

Question: for the interval [a, B], calculate how many of them do not contain '4' and do not contain '62', 1 <a, B <= 10 ^ 15;

Digital DP Solution. dp [I] [j] indicates the number of I-bits starting with j.

For example, dp [2] [6] represents 60, 61, 66, 69;

Dp [I] [j] = dp [I] [j] + dp [I-1] [k], where 0 <= k <= 9;


# Include <algorithm> # include <iostream> using namespace std; int dp [10] [10]; void init () {dp [0] [0] = 1; // dp [0] [1-9] = 1 can be for (int I = 1; I <= 8; I ++) for (int j = 0; j <10; j ++) // I bit for (int k = 0; k <10; k ++) // I-1 bit if (j! = 4 &&! (J = 6 & k = 2) dp [I] [j] + = dp [I-1] [k];} int solve (int n) {int d [10]; int len = 0; while (n> 0) {d [++ len] = n % 10; n/= 10 ;} d [len + 1] = 0; int ans = 0; for (int I = len; I> = 1; I --) {for (int j = 0; j <d [I]; j ++) {if (j! = 4 &&! (D [I + 1] = 6 & j = 2) ans + = dp [I] [j];} if (d [I] = 4 | (d [I] = 2 & d [I + 1] = 6) break;} return ans ;} int main () {# ifdef xxz // freopen ("in.txt", "r", stdin); # endif // xxz int r, l; init (); while (cin> l> r) {if (r + l = 0) break; cout <solve (r + 1)-solve (l) <endl;} return 0 ;}


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.