题目链接:​​Bomb​

题目大意:给你一个N,问小于等于这个N的数里面“要49”的数有多少个

题目思路:跟不要62类似,数位dp去做就好了

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
ll a[1005],dp[1005][2],n;

ll dfs(ll pos,ll pre,ll sta,bool limit){
if(pos == -1) return 1;
if(!limit&&dp[pos][sta] != -1) return dp[pos][sta];
ll up = limit?a[pos]:9;
ll tmp = 0;
for(ll i = 0;i <= up;i++){
if(pre == 4&&i == 9) continue;
tmp += dfs(pos-1,i,i == 4,limit&&i == a[pos]);
}
if(!limit) dp[pos][sta] = tmp;
return tmp;
}

ll solve(ll x){
ll pos = 0;
while(x){
a[pos++] = x%10;
x/=10;
}
return dfs(pos-1,-1,0,true);
}

int main(){
ll t,n;
memset(dp,-1,sizeof(dp));
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
printf("%lld\n",n-solve(n)+solve(0));
}
return 0;
}