Bomb
Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 12923 Accepted Submission (s): 4619
Problem Description
The 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?
Input
The 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.
Output
For each test case, the output an integer indicating the final points of the power.
Sample Input
3
1
50
500
Sample Output
0
1
15
Hintfrom 1 to $, the numbers that include the Sub-sequence "49", "149", "249", "349", "449", "490", "491", "492", "493" , "494", "495", "496", "497", "498", "499",
So the answer is 15.
Test instructions [Find the number of ' 49 ' in 1 to n]
* * "Solving" "Digital DP"
"State: F[i][j" indicates the number of all numbers in the number of digits that are valid (excluding "49") for the I-digit number starting with J. 】
"Transfer: if (j!=4| | k!=9) F[i][j]+=f[i-1][k]; Enumeration JK is the beginning of the I and i-1 digits respectively and satisfies the condition. 】
"When solving, subtract the DP value from the total. 】
"In fact, the DP is the first DP, then the data to find the items that meet the requirements" * *
#include <cstdio>#include <cstring>#include <algorithm>#define LL Long Longusing namespace STD; ll N,t;ll f[ -][ -],h[ -],ans;voidDP () {f[0][0]=1;intI,j,k; for(k=1;k< -; ++k) for(i=0;i<Ten; ++i) for(j=0;j<Ten; ++j)if(i!=4|| j!=9) f[k][i]+=f[k-1][J];}inlinell Math (ll N) {ll i,j,tot=0, sum=0;memset(H,0,sizeof(h)); while(n) h[++tot]=n%Ten, n/=Ten; h[1]++; for(i=1; i<=tot;++i)if(h[i]>=Ten) h[i+1]+=h[i]/Ten, h[i]%=Ten;if(h[tot+1]) tot++; for(i=tot;i>0; i--) { for(j=0; jif(j!=9|| h[i+1]!=4) Sum+=f[i][j];if(h[i]==9&&h[i+1]==4) Break; }returnSum }intMain () {intI DP ();scanf("%i64d", &t); for(i=1; i<=t;++i) {scanf("%i64d", &n); Ans=math (n); Ans=n-ans; ans++;printf("%i64d\n", ans); }return 0;}
[Nest is the first time to write a digital DP ...]
"HDU 3555" Bomb