The daily selection problem of meow haha

Source: Internet
Author: User

The daily selection problem of meow haha
Time limit:2000/1000ms (java/others) Memory limit:128000/64000kb (java/others)
Problem Description

Meow haha village TTT classmate is more strange, he hated a kind of number, which is it?

is to hate the numbers that contain 37 or 4.

Like 21379,123485,12379.

But he does not hate the number 928357 because he does not contain 37, nor does he have 4.

Now you [L,r] in the interval, ask you in this interval, the maximum number of TTT students can choose how many do not hate?
Input

Enter two integers to represent L and R

1 <= L <= R <= 2000000000.
Output
Outputs an integer that represents the number of selected numbers
Sample Input

1 10

Sample Output

9

The idea of solving problems: digital DP

#include <cstdio>intdp[ the][ the];intSolveintN) {intCNT =0, ans=0, num[ the]; while(N >0) {num[++cnt] = n%Ten; N/=Ten; } num[cnt+1] =0; for(inti = CNT; i >0; i--) { for(intj =0; J < Num[i]; J + +) {if(J! =4&&! (num[i+1] ==3&& J = =7)) ans + = dp[i][j]; }if(Num[i] = =4|| (Num[i] = =7&& num[i+1] ==3)) Break; }returnAns;}intMain () {intL, R; dp[0][0] =1; for(inti =1; I <=Ten; i++) for(intj =0; J <Ten; J + +) for(intK =0; K <Ten; k++)if(J! =4&&! (J = =3&& k = =7)) Dp[i][j] + = dp[i-1][K]; while(SCANF ("%d%d", &l, &r)! = EOF)printf("%d\ n", Solve (r+1)-Solve (L));return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The daily selection problem of meow haha

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.