Problem DescriptionThe Counter-terrorists found a time bomb in the dust. But this time, the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If The current number sequence includes the Sub-sequence "a", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
Inputthe first line of input consists of an integer t (1 <= T <= 10000), indicating the number of test cases. For each test case, there'll be is an integer N (1 <= n <= 2^63-1) as the description.
The input terminates by end of file marker.
Outputfor each test case, output an integer indicating the final points of the power.
Sample Input
3150500
Sample Output
0115 this is a digital DP, which is a bit simpler than 62. #include <stdio.h> #include <string.h>__int64 dp[25][5]; int a[20];void init () {int i,j;Dp[0][0]=1; Dp[0][0]=1 here is still very important to discuss this number of bits when usefuldp[1][0]=10;dp[1][1]=1;dp[1][2]=0;for (i=2;i<=20;i++) {dp[i][0]=dp[i-1][0]*10-dp[i-1][1];//means no more than I-digit number without 49DP[I][1]=DP[I-1][0]; Represents a number not exceeding the I-digit number without 49 and a maximum of 9dp[i][2]=dp[i-1][2]*10+dp[i-1][1];//represents a number of 49 with no more than I digits}}__int64 cal (__int64 N)//calculated is [0,n-1], where n is not 49 of the number is not judged and not counted in {int I,j,len=0,flag;__int64 num=0;memset (A,0,sizeof (a));while (n) {A[++LEN]=N%10;N=N/10;}if (len==1) return 0;flag=0; Judging if there's already 49 in front.for (i=len;i>=1;i--) {NUM=NUM+A[I]*DP[I-1][2];if (flag) num=num+a[i]*dp[i-1][0];if (!flag && a[i]>4) num=num+dp[i-1][1];if (a[i]==9 && a[i+1]==4) flag=1;}return num;} int main () {int t,m,i,j;__int64 N;Init ();scanf ("%d", &t);while (t--){scanf ("%i64d", &n);printf ("%i64d\n", Cal (N+1));}return 0;}
hdu3555 Bomb (to 49)