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? 

InputThe 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. 
OutputFor 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<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
const int N=;
LL dp[N][][][],n,ans;
int a[N],cnt;
void _divide(LL v){
cnt=;
while(v){
a[++cnt]=v%;
v/=;
}return ;
}
LL _dfs(int pos,bool limit,bool pre,bool stat)
{
if(pos==) return stat;
LL tmp=;
if(!limit&&dp[pos][limit][pre][stat]) return dp[pos][limit][pre][stat];
int Up=limit?a[pos]:;
for(int i=;i<=Up;i++)
tmp+=_dfs(pos-,limit&&i==Up,i==,stat||(pre&&i==));
dp[pos][limit][pre][stat]=tmp;
if(tmp>ans) ans=tmp;
return tmp;
}
int main()
{
int i,T;
scanf("%d",&T);
while(T--){
memset(dp,,sizeof(dp));
scanf("%lld",&n);
_divide(n);
printf("lld\n",_dfs(cnt,true,false,false));
}
return ;
}

HDU3555 Bomb 数位DP第一题的更多相关文章

  1. hdu3555 Bomb (数位dp入门题)

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

  2. hdu3555 Bomb(数位dp)

    题目传送门 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  3. HDU3555 Bomb —— 数位DP

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

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

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

  5. hdu3555 Bomb 数位DP入门

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

  6. HDU3555 Bomb[数位DP]

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

  7. Bomb 数位dp

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

  8. HDU 2089 不要62(数位dp模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意:求区间内不包含4和连续62的数的个数. 思路: 简单的数位dp模板题.给大家推荐一个好的讲解博客.h ...

  9. 【hdu3555】Bomb 数位dp

    题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...

随机推荐

  1. C# Winform实现手机号码归属地查询工具

    摘要:本文介绍使用C#开发基于Winform的手机号码归属地查询工具,并提供详细的示例代码供参考. 一.需求描述 输入正确的手机号码,查询该号码的归属地和其他相关信息. 二.需求分析 1.实现手机号码 ...

  2. Yii框架(一)

    这里接触了 MVC 设计模式中的控制器和视图部分. 创建了一个操作作为控制器的一部分去处理特定请求. 然后又创建了一个视图去构造响应内容. 在这个小例子中,没有模型调用,唯一涉及到数据的地方是 mes ...

  3. Codeforces Round #359 (Div. 2) C. Robbers' watch 鸽巢+stl

    C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. django教程目录

    什么是web框架? Do a web framework ourselves MVC和MTV模式 django的流程和命令行工具 Django的配置文件(settings) Django URL (路 ...

  5. Mac下配置NDK环境

    下载NDK 这里写图片描述配置NDK开发环境 第一步:打开Mac终端 Snip20170208_1.png 第二步:在终端中输入:open -e .bash_profile,打开.bash_profi ...

  6. 对reducers 理解

    var reducers = { totalInEuros : function(state, item) { return state.euros += item.price * 0.8974243 ...

  7. 初识HTML和CSS2

    上节作业问题: 1.css重用 <style> 如果整个页面的宽度 > 900px时: { .c{ 共有 } .c1{ 独有 } } .c2{ 独有 } </style> ...

  8. 《高级Web应用程序设计》疑难杂症(201709011)

    (提供答案的同学,可获得加分小星星,每题1分,总分哦.) 1.DisplayColumn特性加在模型类上,它的用途是什么?

  9. linux限定用户目录及权限

    setfacl -m u:username:rwx dir/file   -m:添加或者修改 u[设置用户]:username[用户名]:rwx[设置权限] g[设置组]:groupname[组名]: ...

  10. 【Windows】Python脚本随机启动

    Python脚本的管理在linux系统上市非常方便的,在windows则不是很方面.但是由于之前对于Windows这块的内容不是很了解,其实计划任务也是不错的,但和linux相比起来还是欠缺了那么点. ...