The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
 
Input
The first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description.

The input terminates by end of file marker.

 
Output
For each test case, output an integer indicating the final points of the power.
 
Sample Input
3
1
50
500
 
Sample Output
0
1
15

Hint

From 1 to 500, the numbers that include the sub-sequence "49" are "49","149","249","349","449","490","491","492","493","494","495","496","497","498","499",
so the answer is 15.

数位dp,找子序列‘49’

记一下有没有出现过'4',是否已经出现过"49"

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len;
LL f[][][];
int d[];
inline LL dfs(int now,int dat,int sat,int fp)
{
if (now==)return sat;
if (!fp&&f[now][dat][sat]!=-)return f[now][dat][sat];
LL ans=,mx=(fp?d[now-]:);
for (int i=;i<=mx;i++)
{
if (sat||!sat&&dat==&&i==)ans+=dfs(now-,i,,fp&&mx==i);
else ans+=dfs(now-,i,,fp&&mx==i);
}
if (!fp&&f[now][dat][sat]==-)f[now][dat][sat]=ans;
return ans;
}
inline LL calc(LL x)
{
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)
sum+=dfs(len,i,,i==d[len]);
return sum;
}
int main()
{
memset(f,-,sizeof(f));
int T=read();
while (T--)n=read(),printf("%lld\n",calc(n));
}

hdu 3555

[暑假集训--数位dp]hdu3555 Bomb的更多相关文章

  1. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  2. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  3. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  4. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...

  5. [暑假集训--数位dp]hdu5787 K-wolf Number

    Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...

  6. [暑假集训--数位dp]UESTC250 windy数

    windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Inp ...

  7. [暑假集训--数位dp]LightOJ1140 How Many Zeroes?

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  8. [暑假集训--数位dp]LightOj1032 Fast Bit Calculations

    A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...

  9. [暑假集训--数位dp]hdu5898 odd-even number

    For a number,if the length of continuous odd digits is even and the length of continuous even digits ...

随机推荐

  1. C++利用偏移量对文件操作

    对输入流操作:seekg()与tellg()对输出流操作:seekp()与tellp()下面以输入流函数为例介绍用法: seekg()是对输入文件定位,它有两个参数:第一个参数是偏移量,第二个参数是基 ...

  2. x86,x64,i386,i686

    x64其实就是64位, x86其实就是32位. 1. i386 适用于intel和AMD所有32位的cpu.以及via采用X86架构的32的cpu. intel平台包括8086,80286,80386 ...

  3. Android深度探索总结

    Android深度探索前四章总结 通过这几章的学习真实体会到“移植”的概念:为特定设备定制Android的过程,但是移植的过程中开发最多的就是支持各种硬件设备的Linux驱动程序,本章对Android ...

  4. OpenCV3.42+VS2017配置+模块计算机类型“X86”与目标计算机类型“x64”冲突”的问题解决

    目录 OpenCV3.42+VS2017配置 Visual Studio 2017 第三方依赖设置,附加依赖项和附加库目录 "fatal error LNK1112: 模块计算机类型&quo ...

  5. 02Qt信号与槽(1)

    信号与槽 1.概述 ​ 信号和槽机制是 Qt 的核心机制,信号和槽是一种高级接口,应用于对象之间的通信,它是 Qt 的核心特性,也是 Qt 区别于其他工具包的重要地方.信号和槽是 Qt 自行定义的一种 ...

  6. 【linux】【指令集】查看是否打开selinux

    > getenforce selinux相关原理资料参考 <鸟哥的linux私房菜>  http://cn.linux.vbird.org/linux_server/0210netw ...

  7. 科学计算库Numpy——概述

    Numpy主要用于数组的各种计算. 导入Numpy import numpy as np 数组类型 Numpy的数组类型为numpy.ndarray. array=np.array([1,2,3,4, ...

  8. Python基础——字典(dict)

    由键-值对构建的集合. 创建 dic1={} type(dic1) dic2=dict() type(dic2) 初始化 dic2={'hello':123,'world':456,'python': ...

  9. manjaro kde tim QQ

    deepin-wine-tim

  10. sqlmanagementstudio2008下载地址

    http://big.wy119.com/sqlmanagementstudio2008_x86_chs.zip