Bomb

                      Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
                            Total Submission(s): 11804    Accepted Submission(s): 4212

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

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.

 
Author
fatboy_cw@WHU
 
Source

【思路】

数位DP。

   预处理:

f[i][0] 表示i位数中不含49的数的数目

f[i][1] 表示i位数中不含49且最高位为9的数的数目

f[i][2] 表示i位数中含49的数的数目

根据n的每一位统计ans,具体见代码。

【代码】

 #include<cstdio>
using namespace std; typedef long long LL;
LL f[][];
/*
f[i][0] i位数 无49存在
f[i][1] i位数 无49存在且末尾为9
f[i][2] i位数 有49
*/
int b[]; void init() {
f[][]=; f[][]=f[][]=;
for(int i=;i<;i++) {
f[i][]=*f[i-][]-f[i-][];
f[i][]=f[i-][];
f[i][]=*f[i-][]+f[i-][];
}
} int main() {
int T; LL n;
scanf("%d",&T);
init();
while(T--) {
scanf("%I64d",&n);
int len=;
while(n)
b[++len]=n% , n/=;
b[len+]=;
LL ans=; bool flag=;
for(int i=len;i;i--) {
ans += b[i]*f[i-][]; // + ...49...
if(flag) ans += f[i-][]*b[i]; // + 49...(无49...)
else if(b[i]>) ans += f[i-][]; // + 4(9 无49)
if(b[i+]== && b[i]==) flag=;
}
if(flag) ans++; //算上自身
printf("%I64d\n",ans);
}
return ;
}

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

  1. HDU 3555 Bomb 数位dp

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

  2. HDU 3555 Bomb 数位DP 入门

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

  3. HDU - 3555 - Bomb(数位DP)

    链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...

  4. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  5. HDU(3555),数位DP

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

  6. HDU 3555 Bomb (数位DP-记忆化搜索模板)

    题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...

  7. hud 3555 Bomb 数位dp

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

  8. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

  9. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  10. HDU 3555 Bomb(数位DP模板啊两种形式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...

随机推荐

  1. Undefined symbols for architecture armv7: "_OBJC_METACLASS_$_ _OBJC_CLASS_$_ ld: symbol(s) not found for architecture armv7错误

    Undefined symbols for architecture armv7:  "_OBJC_METACLASS_$_MWPhotoBrowser", referenced ...

  2. mysql修改字符集 转载

    查看编码:    show variables like 'collation_%';    show variables like 'character_set_%';    修改:    MySQ ...

  3. C#程序中:如何向xml文件中写入数据和读取数据

    xml文件作为外部信息存储文件使用简单,方便,其结构和表格略有相似,下面简单的说一下xml文件内容的读取 …… using System.Xml;using System.IO;namespace W ...

  4. DevExpress 控件使用之XtraReport

    DevExpress 系列控件,相信大家做WinForm开发已经再熟悉不过了.报表工具对大家来说,选择面很广,.net 本身也提供了非常好的设计工具.下面主要介绍通过DevExpress XtraRe ...

  5. 2、Python djang 框架下的word Excel TXT Image 等文件的下载

    2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...

  6. Js 获取 本周、本月起始时间

    涉及到显示本月或本周相关信息,又不想让php去判断,只好直接用js去计算,麻烦了好一阵,还是老老实实的看了下js的日期函数.现总结一下: //计算本周起始日期,并以 Y-m-d 形式返回.    fu ...

  7. Delphi 停靠技术的应用

    一.基础知识介绍 1.VCL组件的基础知识 在TWinControl类中有一个DockSite属性(boolean),它的作用是是否允许别的控件停靠在它的上面:在TControl类中有一个DragKi ...

  8. 关于UPdate用法的

    updaterestore_base  set  restore_base.localcost =(select   localcost  from    [nt2000\cpi].chongia2. ...

  9. HDFS 搭建记录

    1. 三台服务: 172.17.0.62(namenode) 172.17.0.68(datanode) 172.17.0.76(datanode) /etc/hosts包含的内容: 三台都包含的域名 ...

  10. 学习Swift -- 拓展

    拓展(Extension) 扩展就是向一个已有的类.结构体.枚举类型或者协议类型添加新功能.这包括在没有权限获取原始源代码的情况下扩展类型的能力(即逆向建模).扩展和 Objective-C 中的分类 ...