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,具体见代码。

【代码】

  1. #include<cstdio>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. LL f[][];
  6. /*
  7. f[i][0] i位数 无49存在
  8. f[i][1] i位数 无49存在且末尾为9
  9. f[i][2] i位数 有49
  10. */
  11. int b[];
  12.  
  13. void init() {
  14. f[][]=; f[][]=f[][]=;
  15. for(int i=;i<;i++) {
  16. f[i][]=*f[i-][]-f[i-][];
  17. f[i][]=f[i-][];
  18. f[i][]=*f[i-][]+f[i-][];
  19. }
  20. }
  21.  
  22. int main() {
  23. int T; LL n;
  24. scanf("%d",&T);
  25. init();
  26. while(T--) {
  27. scanf("%I64d",&n);
  28. int len=;
  29. while(n)
  30. b[++len]=n% , n/=;
  31. b[len+]=;
  32. LL ans=; bool flag=;
  33. for(int i=len;i;i--) {
  34. ans += b[i]*f[i-][]; // + ...49...
  35. if(flag) ans += f[i-][]*b[i]; // + 49...(无49...)
  36. else if(b[i]>) ans += f[i-][]; // + 4(9 无49)
  37. if(b[i+]== && b[i]==) flag=;
  38. }
  39. if(flag) ans++; //算上自身
  40. printf("%I64d\n",ans);
  41. }
  42. return ;
  43. }

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. jQuery HTML CSS 方法

    jQuery HTML / CSS 方法 下面的表格列出了所有用于处理 HTML 和 CSS 的 jQuery 方法. 下面的方法适用于 HTML 和 XML 文档.除了:html() 方法. 方法 ...

  2. JavaScript中Ajax的get和post请求

    AJAX = 异步 JavaScript和XML(Asynchronous JavaScript and XML) 作用:在不重新加载整个网页的情况下,对网页的某部分进行更新.   两种请求方式: 1 ...

  3. java中关于static的小知识

    static能够修饰属性和方法.凡是static修饰的方法和属性都是和类的关系较大,都在加载的时候要特殊处理(包括属性和类的优先加载).下面比较下static修饰属性和方法时的区别: 一.修饰属性的时 ...

  4. ACM HDU 1021 Fibonacci Again

    #include<iostream> using namespace std; int main() { int n; while(cin>>n) { if((n+1)%4== ...

  5. Centos 6.5 RedHat 6 安装mysql

    所需文件列表, 这些文件在安装光盘内的Packages文件夹内, 也可以到MySQL官方网站下载其他版本(需要FQ). 将这些文件放在/usr/loca/src文件夹: -.el6.x86_64.rp ...

  6. npm install express -g出错

    npm ERR! Windows_NT npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program ...

  7. ThinkPHP表单令牌验证功能详细介绍

    注:TP版本为3.1.3 在ThinkPHP框架下,两次提交同一个表单,比如提交信息后在浏览器点击后退退回上次的页面,重新点击提交按钮,就会提示“表单令牌错误”的信息. ThinkPHP新版内置了表单 ...

  8. 关于java reflect

    反射的基石 Class类 对比提问: Person类代表人,它的实例对象就是张三,李四这样一个个具体的人, Java程序中的各个Java类属于同一类事物,描述这类事物的Java类名就是Class.对比 ...

  9. jquery GET POST

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <head> ...

  10. 浅析Linux操作系统工作的基础

    环境:lubuntu 13.04   kernel 3.9.7 作者:SA12226265 katao 简介: 本文根据 Linux™ 系统工作基础的分析,对存储程序计算机.堆栈(函数调用堆栈)机制和 ...