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. Css常用属性单位

    长度单位:px-像素 颜色单位:         ①十六进制:#FFFFFF:         ②颜色名称:red:         ③RGB颜色代码:RGB(0-255,0-255,0-255): ...

  2. 解题报告:poj 3070 - 矩阵快速幂简单应用

    2017-09-13 19:22:01 writer:pprp 题意很简单,就是通过矩阵快速幂进行运算,得到斐波那契数列靠后的位数 . 这是原理,实现部分就是矩阵的快速幂,也就是二分来做 矩阵快速幂可 ...

  3. UVa 11324 最大团(强连通分量缩点)

    https://vjudge.net/problem/UVA-11324 题意:给一张有向图G,求一个结点数最大的结点集,使得该结点集中任意两个结点u和v满足,要么u可以到达v,要么v可以达到u. 思 ...

  4. C++中输入输出十六进制八进制

    本文参考链接:https://www.cnblogs.com/hxsyl/archive/2012/09/18/2691693.html,经重新实验得此文 1.进制问题 默认情况下使用cin和cout ...

  5. jQuery 中$.ajax()方法参数详解

    $.ajax({ url:'test.do', data:{id:,name:'xiaoming'}, type:'post', dataType:'json', success:function(d ...

  6. Pytorch入门笔记

    import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): #nn. ...

  7. sqlserver数据库标注为可疑的解决办法

    前几天客户那边的服务器死机了,然后客户强制关机,重新启动服务器后,系统就没法正常使用,连接不上服务器,我远程操作后,看到数据库标注为可疑,由于客户之前没备份数据库,看来只能是修复了: 1:停止数据库服 ...

  8. IOS-网络(网页开发-UIWebView,HTML,CSS,JavaScript,OC和JS代码互调)

    一.网页基础 // // ViewController.m // IOS_0218_网页开发1 // // Created by ma c on 16/2/18. // Copyright © 201 ...

  9. ssh原理与应用

    一.什么是SSH? 简单说,SSH是一种网络协议,用于计算机之间的加密登录. 如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登录是安全的,即使被中途截获,密码也不会 ...

  10. jquery动态创建元素 div元素随垂直滚动条位置变化置顶显示

    刚打开页面效果 拖动滑动条之后效果 页面代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...