BombTime
limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 9343 Accepted Submission (s): 3303
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
0115Hintfrom 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.
Author[email protected]
Source2010 acm-icpc multi-university Training Contest (--host by WHU)
Contains 49 of the number.
#include <cstdio> #include <algorithm> #include <cstring> #include <iostream> #include < Cmath> #define N 1010#define ll long longusing namespace Std;ll dp[30][3];//0: Legal 1:9 Opening 2: illegal///dp[i][j] J-State void Init () {memset (dp,0,sizeof dp) of length I; Dp[0][2]=1; for (int i=1; i<=24; i++) {dp[i][0]=dp[i-1][0]*10+dp[i-1][1]; DP[I][1]=DP[I-1][2]; DP[I][2]=DP[I-1][2]*10-DP[I-1][1]; }}ll Solve (ll n) {int a[40]; int len=1; while (n) {a[len++]=n%10; n/=10; } a[len]=0; ll Ans=0; int flag=0; for (int i=len-1; i>=1; i--) {ans+=dp[i-1][0]*a[i]; if (flag) ans+=dp[i-1][2]*a[i]; if (!flag&&a[i]>4) ans+=dp[i-1][1]; if (a[i]==9&&a[i+1]==4)///xx49*** the case * is to fill the digit flag=1; } return ans; int main () {init (); int t; cin>>t; while (t--) {ll n; cin>>n; printf ("%i64d\n", Solve (n+1)); } return 0;}
HDU 3555 Bomb (digital DP)