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. VS2010对Excel操作---DLL向

    最近公司有个项目要用到Excel的操作,于是自己就对VC中关于Excel的操作进行整理了下.而这里我是直接做成DLL方便他人调用的. 创建一个MFC Dll项目. 选择MFC扩展DLL. 在“类视图” ...

  2. Angularjs总结(二)过滤器使用

    html页面: <table> <thead> <tr> <td class="td">序号</td> <td c ...

  3. SQL SERVER while循环

    在SQL数据库中,可以通过WHILE实现循环,下面就将为您介绍SQL循环执行while控制,希望对您提升WHILE的使用水平能够有些帮助. WHILE Boolean_expression    { ...

  4. Javascript字符串拼接小技巧

    在Javascript中经常会遇到字符串的问题,但是如果要拼接的字符串过长就比较麻烦了. 如果是在一行的,可读性差不说,如果要换行的,会直接报错. 在此介绍几种Javascript拼接字符串的技巧. ...

  5. 使用APPLICATION制作缓存,转存一下,有一段写的还可以。

    public sealed class CacheManager   {   private HttpApplicationState appPool = null;   /// <summar ...

  6. oracle查看用户信息

    1.查看所有用户:select * from dba_users; select * from all_users; select * from user_users;2.查看用户或角色系统权限(直接 ...

  7. 网站开发常用jQuery插件总结(二)弹出层插件Lightbox_me

    网站开发过程中,为了增加网站交互效果,我们有时需要在当前页面弹出诸如登陆.注册.设置等窗口.而这些窗口就是层,弹出的窗口就是弹出层.jQuery中弹出层插件很多,但有些在html5+css3浏览器下, ...

  8. Xcode 插件开发

    我最近一年来都在开发ios应用,不过感觉公司的app维护起来非常麻烦. 因为公司要为很多个企业订做app,每个app的功能基本相同,只是界面上的一些图片和文字要换掉,功能也有一些小改动.考虑到代码维护 ...

  9. 修改虚拟机linux硬盘的大小

    一.概述 Ubuntu用了一段时间,系统已从原来的4G增长到8G,导致虚拟磁盘不够用,需要修改虚拟硬盘的大小. 但是,修改虚拟机硬盘的大小不像修改内存那么简单,操作一个滑动条就轻松搞定.要知道虚拟硬盘 ...

  10. ligerUI路径问题

    ligerUI放mv的Content目录下,路径为固定的并且必须引进一下文件 <link href="~/Content/Ligerui/Source/lib/ligerUI/skin ...