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. Python连接mongodb提取部分字段内数据并写入txt文件

    #coding=utf-8 import sys reload(sys) sys.setdefaultencoding('utf-8') from pymongo import MongoClient ...

  2. 启动sping的时候可以使用system.in.read()暂停

    启动sping的时候可以使用system.in.read()暂停 只要不输入就可以不会停了:

  3. Spring 配置多个数据源,并实现动态切换

    1.配置两个不同的数据源,如下 <!-- 数据源配置1 --> <bean id="testDataSource1" class="com.alibab ...

  4. 载入本地Html文件

    NSString * resousePath = [[NSBundle mainBundle]resourcePath];         NSString * filePath = [resouse ...

  5. Transform.Translate 平移

    function Translate (translation : Vector3, relativeTo : Space = Space.Self) : void Description描述 Mov ...

  6. axios 处理并发请求

    //同时发起多个请求时的处理 axios.all([get1(), get2()]) .then(axios.spread(function (res1, res2) { // 只有两个请求都完成才会 ...

  7. Sencha Test Futures API 探秘

    原文链接:http://blog.csdn.net/lovelyelfpop/article/details/52301249 英文原文:<Inside the Sencha Test Futu ...

  8. linux ln 命令使用参数详解(ln -s 软链接)(转)

    这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln -s 源文件 目标文件. 当 我们需要在不同的 ...

  9. Android中database所在文件夹路径(9.6)

    1 sd----->data---->对应app---->databases----->创建的db 2 push到pc上,可以使用GUI工具SQLiteSpy直接查看datab ...

  10. c#关于路径的总结(转) 虚拟路径波浪号~和斜杠/的区别

    c#关于路径的总结(转)   来源:http://www.cnblogs.com/yugongmengjiutian/articles/5521165.html 前一段时间写代码时经常遇到获取路径问题 ...