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. Python中ndarray数组切片问题a[-n -x:-y]

    先看看如下代码: >>a=np.arange(10)>>a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])>>a[-7:] array( ...

  2. 百度地图 Javascript API 笔记

    因为最近的一个项目用到,所以自己整理了一下遇到的一些坑 自己写了一个类库来二次封装用于调起常用的功能:https://github.com/iRuxu/iBMap 快速文档链接 Javascript ...

  3. Linux的磁盘分区(二)

    LVM逻辑卷机制 PV(Physical Volume 物理卷) - 物理分区或整个物理磁盘 - 由PE(Physical Extent,基本单元)租场 VG(Volume Group 卷组) - 一 ...

  4. OpenGl中的Nurbs B样条曲面绘制

    NURBS 贝塞尔曲线的缺点是当我们增加很多控制点的时候,曲线变得不可控,其连续性会变差差.如果控制点很多(高阶曲线),当我们调整一个控制点的位置,对 整个曲线的影响是很大的.要获得更高级的控制,可以 ...

  5. Hook ptrace 调试加入了ptrace函数的程序

    Hook ptrace 调试加入了ptrace函数的程序 #import <substrate.h> #if !defined(PT_DENY_ATTACH)#define PT_DENY ...

  6. linux系统上查看硬件信息

    一:查看CPU more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  7. 推荐两款国人开发的html前段框架

    1.http://www.h-ui.net/  H-ui前端框架官方网站 2.http://www.builive.com/  BUI是基于JQuery的富客户端UI框架

  8. asp:Repeater数据源为空时处理方式

    当Repeater的数据源为空时,会显示空白,界面不友好,以下方式可以简单处理. <asp:repeater runat="server" id="rplist2& ...

  9. Syncthing源码解析

    Gogland编译Syncthing 源码目录说明 Syncthing启动过程分析 在Gogland中对Syncthing的各个模块进行调试 第三方库

  10. windows挂载网络盘

    @echo offset filename=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%set filename="DataBak-%filename%"ne ...