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