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. Ubuntu系统降内核

    本人安装的Ubuntu16.04.6系统原生内核为4.15.0,但安装的应用仅支持4.8.0以下内核,因此需要降内核.PS:降内核有风险,操作前请慎重 1.查看可用的内核 输入命令查看已经可用的内核 ...

  2. django中的缓存 跨域问题(同源策略)

    django缓存机制 在动态网站中,用户所有的请求,服务器都会去数据库中进行相应的增,删,查,改,渲染模板,执行业务逻辑,最后生成用户看到的页面. 当一个网站的用户访问量很大的时候,每一次的的后台操作 ...

  3. centos7 yum安装nginx和 编译安装tengine

    说明 我这里给大家演示一下如何安装nginx,nginx我就不多介绍了,然后我再说一点就是,安装的两种方法都可以,编译安装和yum安装,我不能每个都演示两遍呀,所以看到我这博客的你,学会举一反三好吧? ...

  4. vue开发环境配置跨域,一步到位

    本文要实现的是:使用vue-cli搭建的项目在开发时配置跨域,上线后不做任何任何修改,接口也可以访问,前端跨域解决方案 production:产品 生产环境 development:开发 开发环境 1 ...

  5. Redis 使用指南:深度解析 info 命令

    Redis 是一个使用  ANSI C 编写的开源.基于内存.可选持久性的键值对存储数据库,被广泛应用于大型电商网站.视频网站和游戏应用等场景,能够有效减少数据库磁盘 IO, 提高数据查询效率,减轻管 ...

  6. 并不对劲的CF1236D&E:Alice&Doll&UnfairGame

    CF1236D Alice&Doll 题目描述 有一个机器人在一个\(n\times m\)的有\(k\)个障碍网格上移动,上北下南左西右东. 它一开始在第一行第一列,面朝东边.它在每个格子上 ...

  7. Codeforces 1247E. Rock Is Push

    传送门 显然考虑 $dp$ ,设 $fx[i][j]$ 表示从 $(i,j)$ 出发往下走一格,最终到达 $(n,m)$ 的方案数,$fy[i][j]$ 表示从 $(i,j)$ 出发往右走一格,最终到 ...

  8. linux安装字体库(simSun为例)

    在开发过程中,发现报表打印,字体和默认字体不一样.本地开发环境(windows)没问题,但是远程linux一直出现这样的问题.经过排查发现linux没有安装中文字体库宋体. linux查看当前的字体库 ...

  9. spring boot logback无感配置

    spring boot1.5.x版本的日志配置一直有一个问题,就是不能直接通过yml配置文件进行日志文件大小进行动态和方便的配置. 怎么解决?直接在springboot项目的maven工程中的src/ ...

  10. Mybatis 多个参数传入的多种方法

    ist<XXXBean> getXXXBeanList(HashMap map); <select id="getXXXBeanList" parameterTy ...