I. GZP and Csgzp love to play Counter-Strike (CS). One day GZP is playing a mod of CS. 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 is sequence includes the Sub-sequence "", the power of the blast would add one point. Now GZP knows the number N. Only if the computing result of the final points of the power by GZP is correct can he attain success. Can you help him? Inputthe first line of input consists of an integer t (1 <= t <=), 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.Outputfor each test case, output an integer indicating the final points of the power. Sample Input
31100500
Sample Output
015
Hint
From 1 to $, the numbers that include the Sub-sequence "All" is "", "196", "296", "396", "496", and so the answer is 5.
Test Instructions :
Q [1,n] How many of the number contains 96;
Ideas :
The problem of digital DP is the same as that of a HDU digital DP; Alas, there is no understanding of the writing of memory search; have time to see;
AC code :
#include <bits/stdc++.h>using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=1e6+5e5; LL dp[ -][3],n;intb[ -];//Dp[i][0] Indicates that the length of <=i contains 96 of the number;//Dp[i][1] Indicates the number of length I does not contain 96 but begins with 6//Dp[i][2] Indicates that <=i does not contain 96 of the number;intFun () {MST (DP,0); dp[0][2]=1LL; for(intI=1;i< at; i++) {dp[i][0]=dp[i-1][0]*Ten+dp[i-1][1]; dp[i][1]=dp[i-1][2]; dp[i][2]=dp[i-1][2]*Ten-dp[i-1][1]; }}intMain () {intT; scanf ("%d",&t); Fun (); while(t--) {scanf ("%lld",&N); LL Temp=n,ans=0; intCnt=1; while(temp) {b[cnt++]=temp%Ten; Temp/=Ten; } b[cnt]=0; intflag=0; for(intI=cnt;i>0; i--) {ans+=dp[i-1][0]*(LL) b[i]; if(flag)//If the front has already appeared 96 then also to add the number of programs that do not contain 96;{ans+=dp[i-1][2]*B[i]; } if(b[i+1]==9&&b[i]==6) {flag=1; } } if(flag) ans++;//if 96 appears behind, it's all 0.printf"%lld\n", ans); } return 0;}
Sai GZP and CS (digital DP)