标签:int main amp bit lse his power RKE title
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn = 25 ;
ll n,m,k,t,dp[mxn][3],lim[mxn];
ll dfs(int pos , int state , int limit)
{
if(!pos) return 1;
if(!limit && dp[pos][state]!=-1) return dp[pos][state];
int up = limit ? lim[pos] : 9 ;
ll ans = 0 ;
for(int i=0;i<=up;i++)
{
if( ( state && i==9)) continue ;
ans += dfs(pos-1, i==4 , limit && i==lim[pos] ) ;
}
if(!limit) dp[pos][state] = ans;
return ans;
}
ll cal(ll x)
{
int len = 0;
memset(lim,0,sizeof(lim));
memset(dp,-1,sizeof(dp));
while(x) lim[++len] = x%10 , x/=10 ;
return dfs(len,false,true);
}
int main()
{
cin>>t;
while(t--)
{
cin>>n;
cout<<n-cal(n)+1<<endl;
}
return 0;
}
标签:int main amp bit lse his power RKE title
原文地址:https://www.cnblogs.com/Shallow-dream/p/11984970.html