Bomb

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

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.

 
#include<iostream>
#include<string.h>
#define ll long long
using namespace std;
ll shu[], dp[][];
ll dfs(ll len, bool if4, bool shangxian)
{
if (len == )
return ;
if (!shangxian&&dp[len][if4])
return dp[len][if4];
ll mx, cnt = ;//cnt记录的是区间内不含49的个数
mx = (shangxian ? shu[len] : );
for (ll i = ; i <= mx; i++)
{
if (if4&&i == )//如果shu[len]==4&&上一个状态是9
continue;
cnt = cnt + dfs(len - , i == , shangxian&&i == mx);
}
return shangxian ? cnt : dp[len][if4] = cnt;
}
ll solve(ll n)
{
memset(shu, ,sizeof(shu));
ll k = ;
while (n)//将n的每一位拆解出来逆序存在shu[i]中。eg:109,shu[0]=9,shu[1]=0,shu[2]=1;
{
shu[++k] = n % ;//注意这里是++k
n = n / ;
}
return dfs(k, false, true);
}
int main()
{
ll t;
scanf("%lld", &t);
while (t--)
{
ll n;
scanf("%lld", &n);//这里计算的区间是[0,n],题目要计算的是[1,n];
printf("%lld\n", n-(solve(n)-));
//如果是计算区间[a,b];printf(solve(b)-solve(a-1)); }
return ; }

Bomb(要49)--数位dp的更多相关文章

  1. hdu 3555 Bomb 炸弹(数位DP,入门)

    题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...

  2. Bomb HDU - 3555 数位dp

    Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> ...

  3. Bomb 数位dp

    ---恢复内容开始--- 不能有49 数位dp模板题: #include<bits/stdc++.h> using namespace std; //input by bxd #defin ...

  4. 数位dp介绍

    不了解dp的可以先看一下dp 数位dp含义: 数位:一个数有个位,十位,百位,千位等等,数的每一位都是数位. 数位dp归为计数dp,是在数位上进行操作的dp. 数位dp的实质是一种快速枚举的方式,它满 ...

  5. hdu3555 Bomb (记忆化搜索 数位DP)

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

  6. hdu---(3555)Bomb(数位dp(入门))

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

  7. HDU 3555 Bomb 数位dp

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

  8. HDU 3555 Bomb(数位DP)

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

  9. Bomb HDU - 3555 (数位DP)

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

随机推荐

  1. PMP项目管理笔记

    项目管理三重制约:时间.成本.范围.结果:质量(结果质量和过程质量)四个层次:复杂事情简单化:分解简单事情量化:临界值量化的事情专业化:规律专业的事情模板化:框架模板 工作分日常运作和项目.日常运作为 ...

  2. Windows sql语句正则匹配导出数据到本地 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

    尝试使用 into outfile导出数据的时候出现错误: The MySQL server is running with the --secure-file-priv option so it c ...

  3. Plupload 多实例上传 测试可用

    <style type="text/css"> .btn{-webkit-border-radius:3px;-moz-border-radius:3px;-ms-bo ...

  4. swift 学习之UISegmentedControl

    //创建分段控件的标题         let titileArray:[String] = ["点评", "哪里逃"]         let segment ...

  5. Linux 基础教程 39-作业控制

        在Linux系统中,作业是由一个或多个关联进程组成的.用户可以运行多个作业并可以在作业间切换.而作业控制则是对作业的行为进行控制,允许用户对作业的前后台的进行切换和终止操作等.作业相关的控制命 ...

  6. IntelliJ IDEA 2016.1.3(64) license server 与汉化

    license server:http://idea.iteblog.com/key.php 汉化:将resources_cn.jar 复制到安装IDEA安装目录下的lib文件夹中.重新打开即可. r ...

  7. [转]简介Gulp, Grunt, Bower, 和 Npm 对Visual Studio的支持

    本文转自:http://www.cnblogs.com/whitewolf/p/4009199.html [原文发表地址]Introducing Gulp, Grunt, Bower, and npm ...

  8. java try catch finally return执行

    public static int testBasic(){ int i = 1; try{ i++; System.out.println("try block, i = "+i ...

  9. 快速排序(Quicksort)的Javascript实现(转载)

    日本程序员norahiko,写了一个排序算法的动画演示,非常有趣. 这个周末,我就用它当做教材,好好学习了一下各种排序算法. 排序算法(Sorting algorithm)是计算机科学最古老.最基本的 ...

  10. polymer技巧

    1.添加一个div元素 我们完全可以自己造一个这样的东西出来,比如下面例子我们给 div 元素添加一个 is="demo-test" <script> var Poly ...