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. 【数据结构】P1310 表达式的值

    [题目链接] https://www.luogu.org/problem/P1310 题目描述 对于1 位二进制变量定义两种运算: 运算的优先级是: 先计算括号内的,再计算括号外的. “× ”运算优先 ...

  2. 在Windows中 , 如何用leakdiag “自动”检测内存泄露 (自动记录日志)

    一.基本用法 在LeakDiag中选择aaa.exe 然后选择Windows Heap Allocator来跟踪heap的使用,按start开始,等一会按log,然后再stop 会在c:\leakdi ...

  3. ‘mysql’不是内部或外部命令,也不是可运行的程序--解决方法

    一.场景 在cmd命令窗口下操作mysql时,提示mysql不是内部或外部命令,也不是可运行的程序. 二.原因 有3种原因: 1.没有装mysql 2.没有配置mysql环境变量 3.cmd命令窗口没 ...

  4. elment-ui表单验证

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-widt ...

  5. S5PV210 点亮Led

    GPC1CON, R/W, Address = 0xE020_0080 GPC1DAT, R/W, Address = 0xE020_0084 举例 #define GPC1CON *((volati ...

  6. 如何上传HTML5应用到SAP云平台的Cloud Foundry环境下

    先使用WebIDE创建一个HTML5应用.New->Project from Template: 从可选模板里选择SAPUI5 Application: 创建一个HTML5 Module,取名为 ...

  7. Java虚拟机内存基础、垃圾收集算法及JVM优化

    1 JVM 简单结构图   1.1 类加载子系统与方法区 类加载子系统负责从文件系统或者网络中加载 Class 信息,加载的类信息存放于一块称 为方法区的内存空间.除了类的信息外,方法区中可能还会存放 ...

  8. 多线程理论———— threading

    什么是线程 线程也是一种多任务编程方法,可以利用计算机多核资源完成程序的并发执行.线程又被称为轻量级的进程.线程的特征 * 线程是计算机多核分配的最小单位 * 一个进程可以包含多个线程 * 线程也是一 ...

  9. 【Day3】3.提取商城分类结构

    import re with open('index.html','r',encoding='utf-8') as f: html = re.sub('\n','',f.read()) section ...

  10. 看一下我学习linux的过程

    学习Linux的最佳方法是将它用于日常工作. 阅读Linux书籍,观看Linux视频不仅仅是足够的. 学习Linux没有捷径可走. 你不可能在一夜之间在Linux中掌握. 这需要时间和持久性. 刚刚潜 ...