hdu3555 数位dp
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define INF 99999999 #define ll __int64 using namespace std; const int MAXN = 30; ll dp[MAXN][MAXN]; void init() { int i,j,k; memset(dp,0,sizeof(dp)); dp[0][0] = 1; for(i=1; i<=25; i++){ for(j=0; j<=9; j++){ for(k=0; k<=9; k++){ if(!(j==4 && k==9)){ dp[i][j] += dp[i-1][k]; } } } } } ll slove(ll n) { int i,j,digit[30],len; len = 0; memset(digit,0,sizeof(digit)); ll x = n; while(1){ if(!x)break; digit[++len] = x%10; x/=10; } ll ans = 0; for(i=len; i>0; i--){ for(j=0; j<digit[i]; j++){ if(!(digit[i+1]==4 && j==9)) ans += dp[i][j]; } if(digit[i+1]==4 && digit[i]==9) break; } return ans; } int main() { int i,j,t; ll n; init(); cin>>t; while(t--){ cin>>n; cout<<n-slove(n+1)+1<<endl; } return 0; }