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. 【原创】请避免GO语言中的携程空跑(CPU突然激增)

    其实GO语言从1.6版本开始非常不错了,GC性能优化非常到位,并且各种并行设计比从新实现一套C++版本的确是方便不少. 语言包也很多,库也相对稳定,完全可以适用于生产环境. 本文主要是给刚刚入门新手注 ...

  2. Java线程死锁查看分析方法

    如何查看是否有Java线程死锁?下面介绍两种方法. 一.Jconsole        Jconsole是JDK自带的图形化界面工具,使用JDK给我们的的工具JConsole,可以通过打开cmd然后输 ...

  3. deploy: [mkdir] Created dir: C:\Program Files\Java\apache-cxf-2.4.2\samples\java_first_pojo\build [loadfile] Do not set property srcbuild.classpath as its length is 0.

    使用CXF的错误,错误是说我的路径有错误,因为路径错误所以无法运行程序 (1)原因,我将其放入了Program Files文件夹下,所以,其不好使 分析原因: 目录路径错误,目录中不能有空格,否则其解 ...

  4. Spring源码解析 - ListableBeanFactory

    Extension of the {@link BeanFactory} interface to be implemented by bean factories that can enumerat ...

  5. C++智能指针shared_ptr

    shared_ptr 这里有一个你在标准库中找不到的—引用数智能指针.大部分人都应当有过使用智能指针的经历,并且已经有很多关于引用数的文章.最重要的一个细节是引用数是如何被执行的—插入,意思是说你将引 ...

  6. polymer-developer guide-feature overview

    <dom-module id='proto-element'> <template> <div>{{greeting}}</div> </temp ...

  7. (2)-生成JSONObject的方法

    生成JSONObject一般有两种方式,通过javabean或者map类型来生成.如下面的例子:   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  8. SQL -- What Tables Queries are Used to Display the Counts in the Inventory Account Periods form (INVTTGPM.fmb) (Doc ID ID 357997.1)

    Applies to: Oracle Inventory Management - Version 11.5.9 to 12.1.3 [Release 11.5 to 12.1] Informatio ...

  9. 咏南LINUX中间件

    咏南LINUX中间件 什么是跨平台? DELPHI跨平台已经不是停留在理论,而是可以实用了. 同一套中间件既能在WINDOWS服务器上面部署,又可以在LINUX服务器上面部署. 而做到这一切,只需要一 ...

  10. Android-自定义开关(升级版)

    效果图: 定义一个类,取名为MySwitch.java,此类去继承View,为何是继承View而不是去继承ViewGroup呢,是因为自定义开关没有子控件,之需要操作自身绘制即可 package cu ...