当前位置:网站首页>HDU 3555 Bomb
HDU 3555 Bomb
2022-06-26 13:12:00 【YJEthan】
Here's a number n, I want you to ask 0-n How many numbers in contain 49, use n- Not included 49 The number of is the answer .
#include<bits\stdc++.h>
using namespace std;
typedef long long ll;
ll dp[20][10];// Recorded in the i position , The first one is j The number of qualified
int a[20];//
ll dfs(ll pos,ll pre,ll lim)// The current position , The first digit , Whether the previous digit is the maximum number of the previous digit
{
if(pos==-1) return 1;// At this point, all locations have been enumerated , Meet the requirements ;
if(!lim&&dp[pos][pre]!=-1)
return dp[pos][pre];
int up=lim?a[pos]:9;//up Represents the maximum number that can be enumerated
ll ans=0;
for(int i=0;i<=up;i++)
{
if(pre==4&&i==9)
continue;
ans+=dfs(pos-1,i,lim&&i==up);// If the current position has not reached the maximum number , Then there is no limit on the number of the next digit .
}
if(!lim) dp[pos][pre]=ans;// Save the number of qualified current states
return ans;
}
ll solve(ll n)
{
int i=0;
while(n)
{
a[i++]=n%10;
n/=10;
}
return dfs(i-1,0,1);
}
int main()
{
int t;
scanf("%d",&t);
memset(dp,-1,sizeof(dp));
while(t--)
{
ll n;
scanf("%I64d",&n);
printf("%I64d\n",n-solve(n)+1);
}
return 0;
}
边栏推荐
猜你喜欢
组合模式(Composite )
processing 函数translate(mouseX, mouseY)学习
倍福PLC基于CX5130实现数据的断电保持
8、【STM32】定时器(TIM)——中断、PWM、输入捕获实验(一文精通定时器)
享元模式(Flyweight)
详细讲解C语言10(C语言系列)
P2393 yyy loves Maths II
Explain C language 11 in detail (C language series)
Stream learning record
Verilog中的系统任务(显示/打印类)--$display, $write,$strobe,$monitor
随机推荐
Coprime and non coprime of template problems of Chinese remainder theorem
单例的常用创建和使用方式
C - Common Subsequence
PostGIS geographic function
Go 结构体方法
zoopeeper设置acl权限控制(只允许特定ip访问,加强安全)
D - 滑雪
H - Sumsets POJ 2229
National standard gb28181 protocol easygbs video platform TCP active mode streaming exception repair
5月产品升级观察站
Explain C language 11 in detail (C language series)
倍福PLC基于CX5130实现数据的断电保持
This function has none of deterministic, no SQL solution
C# const详解:C#常量的定义和使用
HDU 3555 Bomb
倍福TwinCAT3实现CSV、TXT文件读写操作
Software testing - concept
E - Apple Catching
What should the software test report include? Interview must ask
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control