Bomb

**Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)**

Total submission (s): 15102 Accepted Submission (s): 5452

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 Input3150500

Sample Output0115

*Hint*From 1 to $, the numbers that include the Sub-sequence "is" 49 "," 149 "," 249 "," 349 "," 449 "," 490 "," 491 "," 492 "," 493 "," 49 4 "," 495 "," 496 "," 497 "," 498 "," 499 ", so the answer is 15.

Author[email protected]

Source acm-icpc multi-university Training Contest (--host by WHU)

/*

This is your own code, like "Don't 49", ran 65ms

*/

#include <iostream>#include<stdio.h>#include<vector>#include<algorithm>#include<string.h>#include<cstdio>#defineN 22using namespacestd;Long LongT,n;intG[n];//the number of digits used to hold the numberLong LongDp[n][n];//Dp[i][j][k] Indicates the number of States that the current remaining number of digits is J and is 4 on the current bit .Long LongDfsintLenBOOLSBOOLF//s Indicates whether the current bit is not 4{ if(len<1) return 1; if(!f&&dp[len][s]!=-1) returnDp[len][s]; intFmax=f?g[len]:9; Long LongCur=0; //cout<< "fmax=" <<fmax<<endl; for(intI=0; i<=fmax;i++) { if(s&&i==9)Continue;//no more .Cur+=dfs (len-1, i==4,f&& (i==Fmax)); //cout<< "cur=" <<cur<<endl; } //cout<<cur<<endl; if(!f) Dp[len][s]=cur; returncur;}Long LongSolveLong Longx) { intlen=1; while(x!=0) {G[len++]=x%Ten; X/=Ten; } //for (int i=1;i<=len;i++)//cout<<g[i]; //cout<<endl;memset (dp,-1,sizeofDP); returnDFS (len-1,false,true);}intMain () {//freopen ("In.txt", "R", stdin);scanf"%lld",&t); while(t--) {scanf ("%i64d",&N); printf ("%i64d\n", N-solve (n) +1); } return 0;}

/*In the beginning, it really did not ask for "49". Blog when you look at other people's blog absorption of the essence, the following is to be found, Z[i] array is genius originally I also line is asking but do not know how to say that find 49 should add what, a z[i] perfect solution to find 49 should add how much*/#include<iostream>#include<stdio.h>#include<vector>#include<algorithm>#include<string.h>#include<cstdio>#defineN 30using namespacestd;Long LongT,n;intG[n];//the number of digits used to hold the numberLong Longdp[n][2];//Dp[i][j][k] Indicates the number of States that the current remaining number of digits is J and is 4 on the current bit .Long Longz[n]={1};Long LongDfsintLenBOOLSBOOLF//s Indicates whether the current bit is not 4{ if(len==0) return 0; if(!f&&dp[len][s]>=0) returnDp[len][s]; intFmax=f?g[len]:9; Long LongCur=0; //cout<< "fmax=" <<fmax<<endl; for(intI=0; i<=fmax;i++) { if(s&&i==9) {cur+=f?n%z[len-1]+1: z[len-1];//The current bit found, the rest of the search, directly add on the line, this Riga is the rest of the bit } Elsecur+=dfs (len-1, i==4, f&&g[len]==i); //cout<< "cur=" <<cur<<endl; } //cout<<cur<<endl; returnf?cur:dp[len][s]=cur;}Long LongSolveLong Longx) { intlen=0; while(x) {g[++len]=x%Ten; X/=Ten; } //for (int i=1;i<=len;i++)//cout<<g[i]; //cout<<endl;g[len+1]=0; returnDFS (Len,false,true);}intMain () {//freopen ("In.txt", "R", stdin); for(intI=1; i<n;i++) {Z[i]=z[i-1]*Ten; } scanf ("%lld",&t); Memset (DP,-1,sizeofDP); while(t--) {scanf ("%lld",&N); printf ("%lld\n", Solve (n)); } return 0;}

HDU 3555 Bomb (not 49, digital DP)