https://cn.vjudge.net/contest/194559#problem/H
此题和62的类似。就是找含有49的个数,但是重点在于要求的数很大,一直没过。
#include<iostream>
#include<stdio.h>
#include<string.h>
#define LL __int64
using namespace std;
LL dp[60][5];
long long dig[60];
LL dfs(long long pos,long long pre,long long status,bool limit)
{
if(pos==-1)
return 1;
if(!limit&&dp[pos][status]!=-1)
return dp[pos][status];
long long up=limit?dig[pos]:9;
long long temp=0;
for(long long i=0;i<=up;i++)
{
if((pre==4&&i==9))
continue;
temp+=dfs(pos-1,i,i==4,limit&&i==dig[pos]);
}
if(!limit)
return dp[pos][status]=temp;
else
return temp;
}
LL solve(LL x)
{
LL lala=x;
LL hi=0;
while(x)
{
dig[hi++]=x%10;
x/=10;
}
return lala+1-dfs(hi-1,-1,0,true);
}
int main()
{
long long l;
int yy;
memset(dp,-1,sizeof(dp));
cin>>yy;
for(int i=1;i<=yy;i++)
{
scanf("%I64d",&l);
printf("%I64d\n",solve(l));
}
return 0;
}