Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 15062    Accepted Submission(s):
5437

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.

 
 
//题意 t 组数据,在 1- n 中出现了49的数据个数,n 很大,2^63-1 , 遍历肯定不行。
 
//听说这是数位dp的一道水题,这也是水题吗,我服了
自己想了一阵,只想到了一点点。看了别人的也看了很久,才明白,这篇博客非常详细,我就不赘述了,认真看一定能看懂。
我的与他的dp数组有细微差别,因为我自己理解了写了一遍,稍微注意一下。
 
代码 15ms
 
 #include <stdio.h>
#include <string.h> __int64 dp[][];
//dp[i][0] 含49,数的个数
//dp[i][1] 不含49,但首位是9的数的个数
//dp[i][2] 不含49,数的个数(包含了首位是9的数的个数)
void Init()
{
dp[][]=;
for (int i=;i<=;i++)
{
dp[i][]=dp[i-][]*+dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*-dp[i-][];
}
} __int64 solve(__int64 n)
{
__int64 a[],len=; while (n)
{
a[++len]=n%;
n/=;
}
a[len+]=; __int64 ans=;
int flag=; for (int i=len;i>;i--)
{
ans+=dp[i-][]*a[i];
if (flag) //前面有49就所有情况都是49数了
ans+=dp[i-][]*a[i];
if (!flag&&a[i]>) //加上4 9... 的情况
ans+=dp[i-][];
if (a[i]==&&a[i+]==)//判断是不是 49
flag=;
}
return ans;
} int main()
{
int t;
__int64 n;
Init();
scanf("%d",&t);
while (t--)
{
scanf("%I64d",&n);
printf("%I64d\n",solve(n+));//因为函数功能是 (0,n) 区间的49数,题目要求的是[1,n],所以+1
}
return ;
}
 

O-Bomb(数位dp)的更多相关文章

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

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

  2. HDU 3555 Bomb 数位dp

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

  3. HDU3555 Bomb —— 数位DP

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

  4. hud 3555 Bomb 数位dp

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

  5. Hdu Bomb(数位DP)

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

  6. hdu3555 Bomb(数位dp)

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

  7. HDU 3555 Bomb 数位DP 入门

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

  8. hdu3555 Bomb 数位DP入门

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

  9. Bomb 数位dp

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

  10. 【hdu3555】Bomb 数位dp

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

随机推荐

  1. 发布android apk,Error running app: No target device found.

    https://developer.android.com/studio/run/device.html\ 一台android设备不识别,android文档还挺全 需要安装usb驱动链接里有

  2. Camera图像处理原理及实例分析

    Camera图像处理原理及实例分析 作者:刘旭晖  colorant@163.com  转载请注明出处 BLOG:http://blog.csdn.net/colorant/ 主页:http://rg ...

  3. c:foreach如何输出序号

    关键在于<c:forEach>的varStatus属性,具体代码如下: <table width="500" border="0" cells ...

  4. Node.js 本地Xhr取得Node.js服务端数据的例子

    本以为用XHR取Nodejs http出的一段文字很简单,因为xhr取值和nodejs http出文字都是好弄的,谁知一试不是这回事,中间有个关键步骤需要实现. nodejs http出文字显示在浏览 ...

  5. MySql中文乱码问题(3)

    MySql的client是在dos界面上,然而dos界面默认的字符集编码方式是:GBK (1).MySql字符转换原理图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi ...

  6. Visual Prolog 的 Web 专家系统 (10)

    GENI的核心 -- 推理机(4)求证过程分析 1.GENI知识库结构 专家系统推理机的设计执行,与其知识库结构紧密相关. GENI知识库结构是一棵逻辑推理树. 根节点是animal,即求证的目标. ...

  7. 小计一次linux下渗透方法

    本文转自91ri 踩点 目标域名是XX.com 我们的目标是大站,所以主站一般都挺安全的,所以直接寻找二级目录,运气好时能找到一些开源的cms,运气更好点找到个dede啥的,那就…. 我们直接枚举他域 ...

  8. Linux非阻塞IO(三)非阻塞IO中缓冲区Buffer的实现

    本文我们来实现回射服务器的Buffer.   Buffer的实现   上节提到了非阻塞IO必须具备Buffer.再次将Buffer的设计描述一下: 这里必须补充一点,writeIndex指向空闲空间的 ...

  9. Codeforces Round #254 (Div. 2) B (445B)DZY Loves Chemistry

    推理可得终于结果为2的(n-可分组合数)次方. 问题是怎么求出可分组合数,深搜就可以,当然并查集也能够. AC代码例如以下: 深搜代码!!! #include<iostream> #inc ...

  10. 51单片机 | 并行I/O口扩展实例(74LS244/74LS373/4071)

    并行I/O口扩展实例 //<51单片机原理及应用(第二版)——基于Keil C与Proteus>第四章例4.4 I/O口不能完全用于输入/输出操作,当需要扩展外部存储器时,P0.P2口用作 ...