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. python基础知识十一

    图形软件 使用Python的GUI库——你需要使用这些库来用Python语言创建你自己的图形程序.使用GUI库和它们的Python绑定,你可以创建你自己的IrfanView.Kuickshow软件或者 ...

  2. 2013年10月13日学习:SQL通过图形化界面创建表

    通过SQL2005创建表的方式有两种: 1.通过图形化用户界面来创建表.比较容易出问题,不稳定,容易点错了.不推荐 2.通过命令来创建.大牛都是这样做的,比较好. 通过图形化界面创建:以创建员工表为例 ...

  3. SQL Server T-SQL高级查询【转】

    高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student;   --all 查询所有 select all sex from ...

  4. MySQL 连接数据库

    一.MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格),缺点:密码显示在显示器上,容易泄露. C:\>mysql -h localho ...

  5. php文件锁(转)

    bool flock ( int handle, int operation [, int &wouldblock] );flock() 操作的 handle 必须是一个已经打开的文件指针.o ...

  6. oracle建立表空间

    //创建临时表空间 create temporary tablespace test_temp tempfile 'E:\oracle\product\10.2.0\oradata\testserve ...

  7. 常用sql笔记

    Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,score) 成绩表Teacher(T#,Tname) 教师表问题:1.查 ...

  8. 入门6:PHP 语法基础——循环

    一.for循环 for($i=0;$i<10;$i++){ echo "Hello".$i."</br>"; } 二.while循环 $i = ...

  9. 【转】使用spring @Scheduled注解执行定时任务

    http://blog.csdn.net/sd4000784/article/details/7745947 以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在s ...

  10. [转]基于Spring + Spring MVC + Mybatis 高性能web构建

    http://blog.csdn.net/zoutongyuan/article/details/41379851/ 一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.Angula ...