题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555

题意:上一题是不要62 这个是“不要49”

代码:

  1. #include <stdio.h>
  2. #include <ctime>
  3. #include <math.h>
  4. #include <limits.h>
  5. #include <complex>
  6. #include <string>
  7. #include <functional>
  8. #include <iterator>
  9. #include <algorithm>
  10. #include <vector>
  11. #include <stack>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <list>
  16. #include <bitset>
  17. #include <sstream>
  18. #include <iomanip>
  19. #include <fstream>
  20. #include <iostream>
  21. #include <ctime>
  22. #include <cmath>
  23. #include <cstring>
  24. #include <cstdio>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <string.h>
  28. #include <assert.h>
  29. using namespace std;
  30. #define N 50
  31. using namespace std;
  32. int bit[N];
  33. long long dp[N][3];
  34. /*
  35. dp[i][0]:前i位不含 49 的个数。
  36.    dp[i][1]:前i位不含 49 数且i+1位是4的个数。
  37.   dp[i][2]:前i位含 49 的个数。
  38. */
  39. long long dfs(int pos, int st, bool flag)
  40. {
  41. if (pos == 0) return st == 2;
  42. if (flag && dp[pos][st] != -1) return dp[pos][st];
  43. long long ans = 0;
  44. int u = flag ?
  45. 9 : bit[pos];
  46. for (int d = 0;d <= u;d++)
  47. {
  48. if (st == 2 || (st == 1 && d == 9))
  49. ans += dfs(pos - 1, 2, flag || d<u);
  50. else if (d == 4)
  51. ans += dfs(pos - 1, 1, flag || d<u);
  52. else
  53. ans += dfs(pos - 1, 0, flag || d<u);
  54. }
  55. if (flag) dp[pos][st] = ans;
  56. return ans;
  57. }
  58. long long solve(long long n)
  59. {
  60. int len = 0;
  61. while (n)
  62. {
  63. bit[++len] = n % 10;
  64. n /= 10;
  65. }
  66. return dfs(len, 0, 0);
  67. }
  68. int main()
  69. {
  70. long long n;
  71. int t;
  72. scanf("%d",&t);
  73. while (t--)
  74. {
  75. scanf("%lld", &n);
  76. memset(dp, -1, sizeof(dp));
  77. printf("%lld\n", solve(n));
  78. }
  79. return 0;
  80. }

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 全选、反选问题的记录

    <div id="list"> <ul id="choseList" > <li><input type=" ...

  2. myeclipse中js文件报错

    这几天在myeclipse中添加文件时,会报错,但是代码是从官网上下载的,没有错误,只是myeclipse的检查较为严格.在网上找到解决方案,希望可以帮到强迫症的人. 解决步骤: 1.window→P ...

  3. [算法天天练] - C语言实现约瑟夫环(2)

    Linux下 #include <stdlib.h>#include <stdio.h> int main(){ int n,m,i,s = 0; printf("E ...

  4. C/C++ struct定义、声明、对齐方式

    一.定义/声明方式 第一种:仅有结构体名,不定义/声明变量 struct MyStruct {  int i:     char a[10];     double b; }:第二种:有结构体名,并声 ...

  5. blender--(凹凸贴图)................https://jingyan.baidu.com/article/9f63fb917c4becc8400f0ea8.html

    在blender中直接绘制模型凹凸纹理细节 听语音 | 浏览:32 | 更新:2018-02-20 11:18 1 2 3 4 5 6 7 分步阅读 在blender中为了表现更多的模型细节,我们会常 ...

  6. 梦想CAD控件图层COM接口知识点

    梦想CAD控件图层COM接口知识点 一.新建图层 主要用到函数说明: _DMxDrawX::AddLayer 增加新的图层.详细说明如下: 参数 说明 BSTR pszName 图层名 c#中实现代码 ...

  7. BZOJ1013 + BZOJ1923 + POJ1830 (高斯消元)

    三个题放在一起写了 主要是搞搞模板 在这里简述一下怎么写高斯消元 就和代数里学的加减消元学的一样 把矩阵化为上三角形形式 然后进行回代 同时枚举当前要消元的未知数和当前化简到哪一行了 然后从这一行往后 ...

  8. JSONP 应用

    受限于浏览器的同源安全策略, js 无法发起跨域的请求. 但是 HTML 中的 <script> 标签却可以引入跨域的文件使用. 而 JSONP 就是利用 <script> 的 ...

  9. (转)MySQL中的索引详讲

    序言 之前写到MySQL对表的增删改查(查询最为重要)后,就感觉MySQL就差不多学完了,没有想继续学下去的心态了,原因可能是由于别人的影响,觉得对于MySQL来说,知道了一些复杂的查询,就够了,但是 ...

  10. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...