Bomb

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 16713 Accepted Submission(s): 6128

Problem Description

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

HintFrom 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.

Author

fatboy_cw@WHU

Source

2010 ACM-ICPC Multi-University Training Contest(12)——Host by WHU

/*
数位DP.
f[i][j]表示以j开头的i位数的决策.
倒序存储
最后还要加一位统一开区间处理.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAXN 25
#define LL long long
using namespace std;
LL f[MAXN][MAXN],ans,n;
int t,l,a[MAXN];
void pre()
{
f[0][0]=1;
for(int i=1;i<=20;i++)//枚举位数.
for(int j=0;j<=9;j++)//枚举这一位数.
for(int k=0;k<=9;k++)//枚举上一位数.
{
if(j==4&&k==9) continue;
f[i][j]+=f[i-1][k];
}
return ;
}
void slove()
{
n++;ans=n;
l=0;memset(a,0,sizeof a);
while(n) a[++l]=n%10,n/=10;
a[l+1]=0;
for(int i=l;i;i--)
{
for(int j=0;j<a[i];j++)
{
if(a[i+1]==4&&j==9) continue;
ans-=f[i][j];
}
if(a[i]==9&&a[i+1]==4) break;
}
cout<<ans<<endl;
return ;
}
int main()
{
pre();scanf("%d",&t);
while(t--) cin>>n,slove();
return 0;
}

Hdu Bomb(数位DP)的更多相关文章

  1. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  2. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 3555 Bomb 数位dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...

  4. HDU 3555 Bomb 数位DP 入门

    给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...

  5. HDU3555 Bomb —— 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. hdu---(3555)Bomb(数位dp(入门))

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  7. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  8. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  9. hud 3555 Bomb 数位dp

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

随机推荐

  1. javascript获取当前用户访问的宽带IP地址

    javascript获取当前用户访问的宽带IP地址 <script src="http://pv.sohu.com/cityjson?ie=utf-8"></sc ...

  2. PHP max_input_var设为了1000导致post数组太多时无法接受后面的参数值

    PHP max_input_var设为了1000导致post数组太多时无法接受后面的参数值 下午突然接到格力电话说无法批量设置门店任务,但是在测试环境下无法重现,测试环境下好好的. 然后登陆到生产环境 ...

  3. 用shell脚本安装MySQL-5.7.22-官方版本

    Install_CentOS7_MySQL57_binary.sh #!/bin/bash MySQL_Package=mysql-5.7.22-linux-glibc2.12-x86_64.tar. ...

  4. Iedis - Redis 在IDEA中的可视化工具破解

    2.如何破解 // 如果你没有改动IDEA的话,IDEA的插件库在这个目录下C:\Users\Administrator\.IntelliJIdea2017.3\config\plugins\Iedi ...

  5. Python中的math常用方法总结(转)http://www.cnblogs.com/renpingsheng/p/7171950.html

    python中math模块常用的方法整理   ceil:取大于等于x的最小的整数值,如果x是一个整数,则返回x copysign:把y的正负号加到x前面,可以使用0 cos:求x的余弦,x必须是弧度 ...

  6. IOC+EF+Core项目搭建IOC注入及框架(二)

    配置ServiceCollection /// <summary> /// 表示IServiceCollection的扩展 /// </summary> public stat ...

  7. C调用C++(C++封装以及C对其调用)

    C调用C++(C++封装以及C对其调用) 来源 https://blog.csdn.net/wonengguwozai/article/details/89854781 相关知识提点:很经典的exte ...

  8. MySQL5.7 启动报错:initialize specified but the data directory has files in it. Aborting.

    $ vi /etc/my.cnf ## datadir=/var/lib/mysql, 这个是data保存目录,进入/var/lib/mysql后,查看到确实有数据. #解决方法:将/var/lib/ ...

  9. jmeter连接mysql数据库进行多条语句查询

    前提工作: 1.在jmeter官网下载jmeter包(官网地址:https://jmeter.apache.org/).此外还需下载mysql驱动包,如:mysql-connector-java-5. ...

  10. Kubernetes对象中的PersistentVolume、PersistentVolumeClaim和StorageClass的概念关系

    Kubernetes容器要持久化数据,离不开volume,k8s的volume和Docker原生概念中的volume有一些差别,不过本次不讲这个,本次要明确的是k8s持久化数据用到的几个对象Persi ...