Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 24148    Accepted Submission(s): 9092

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


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
int bit[40];
ll f[40][3];
ll dp(int pos,int st,bool flag)
{
if(pos==0)return st==2;
if(flag&&f[pos][st]!=-1)return f[pos][st];
ll ans=0;
int x=flag?9:bit[pos];
for(int i=0;i<=x;i++)
{
if((st==2)||(st==1&&i==9))
{
ans+=dp(pos-1,2,flag||i<x);
}
else if(i==4)ans+=dp(pos-1,1,flag||i<x);
else ans+=dp(pos-1,0,flag||i<x);
}
if(flag)f[pos][st]=ans;
return ans;
}
ll calc(ll x)
{
int len=0;
while(x)
{
bit[++len]=x%10;
x/=10;
}
return dp(len,0,0);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int t;
scanf("%d",&t);
while(t--)
{
memset(f,-1,sizeof(f));
ll n;
scanf("%lld",&n);
printf("%lld\n",calc(n));
}
return 0;
}

hdu 3555 Bomb(数位dp入门)的更多相关文章

  1. HDU 3555 Bomb 数位DP 入门

    给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...

  2. HDU 3555 Bomb 数位dp

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

  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. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  6. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  7. HDU(3555),数位DP

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

  8. HDU 3555 Bomb (数位DP-记忆化搜索模板)

    题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...

  9. hud 3555 Bomb 数位dp

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

  10. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

随机推荐

  1. 散列查找的C实现

    概念 散列查找,类似与查英文字典的过程.如果我们要查找"zoo"(key)对应的释义(value),我们不会从第一页开始逐页查找(顺序查找),而是直接根据大致的推算(Hash函数) ...

  2. centos7 宝塔php7安装mongodb扩展

    一.下载.解压源码 下载地址:https://pecl.php.net/package/mongodb wget -c https://pecl.php.net/get/mongodb-1.5.3.t ...

  3. 用python库openpyxl操作excel,从源excel表中提取信息复制到目标excel表中

    现代生活中,我们很难不与excel表打交道,excel表有着易学易用的优点,只是当表中数据量很大,我们又需要从其他表册中复制粘贴一些数据(比如身份证号)的时候,我们会越来越倦怠,毕竟我们不是机器,没法 ...

  4. 文件 open 方法

    文件对象方法: 文件对象方法  执行操作 f.close()    关闭文件 f.read([size=-1]) 从文件读取size个字符,当未给定size或给定负值的时候, 读取剩余的所有字符,然后 ...

  5. 【AC自动机】单词

    [题目链接] https://loj.ac/problem/10060 [题意] 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. ...

  6. WEB监控系列第三篇:graphite指南

    一  使用说明 以下是喂数据的方式,但是在实际使用中我们使用statsd来喂数据,请参考我的第四篇文章:statsd指南 喂数据有三种方式: There are three main methods ...

  7. VmWare 网络模式

    VMware虚拟机三种联网方法及原理 一.Brigde--桥接:默认使用VMnet0 1.原理: Bridge 桥"就是一个主机,这个机器拥有两块网卡,分别处于两个局域网中,同时在" ...

  8. SpringBoot实现定时器定时处理任务

    最近在项目中遇到了一个问题, 对于新建的活动, 活动设置了开始时间和结束时间, 也就是数据库中的一个状态码的改变而已. 但是,这里就有问题了, 如何去实现到时间更改活动状态呢? 1. 刚开始的时候,我 ...

  9. C++ STL 之 vector

    #include <iostream> #include <vector> using namespace std; void printVector(vector<in ...

  10. Kubernetes的yaml文件中command的使用

    前面说了init容器initContainers,这主要是为应用容器做前期准备工作的,一般都会用到shell脚本,这就会用到command,这里写写command的用法. command就是将命令在创 ...