Bomb

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

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.

 
Author
fatboy_cw@WHU
 
Source
 
数位dp的比较好的题目把。。
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<cmath>
#define ls (u<<1)
#define rs (u<<1|1)
#define maxn 30
#define ll long long
#define INF 1e18+7
using namespace std;
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
int digit[maxn];
ll dp[maxn][];
ll dfs(int pos,int flag,int limit){
if(pos == -){
return flag == ;//flag等于2的时候代表这个数满足条件
}
if(!limit && dp[pos][flag]!=-){//达到极限且此时dp有值
return dp[pos][flag];
}
ll sum = ;
int e = limit?digit[pos]:;
for(int i=;i<=e;i++){
int have = flag;
if(flag == && i == ){
have = ;
}
if(flag == && i == ){
have = ;//此时为将要完成的状态
}
if(flag == && i!= && i!=){
have = ;
}
sum += dfs(pos-,have,limit&&i==e);
}
if(!limit){//达到极限的情况
dp[pos][flag] = sum;
}
return sum;
}
ll solve(ll n){
int pos = ;
while(n){
digit[pos++] = n%;
n /= ;
}
return dfs(pos-,,);
}
int main(){
int T;
scanf("%d",&T);
while(T--){
ll n;
scanf("%lld",&n);
memset(dp,-,sizeof(dp));
printf("%lld\n",solve(n));
}
return ;
}

hud 3555 Bomb 数位dp的更多相关文章

  1. HDU 3555 Bomb 数位dp

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

  2. HDU 3555 Bomb 数位DP 入门

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

  3. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

  4. HDU - 3555 - Bomb(数位DP)

    链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...

  5. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  6. HDU(3555),数位DP

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

  7. HDU3555 Bomb —— 数位DP

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

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

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

  9. hdu3555 Bomb 数位DP入门

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

随机推荐

  1. 用机智云做PWM占空比控制电机,物联网智能家居应用

      因为是新申请的博客,所以申请了总想往里面加点东西,所以把我之前在机智云写的帖子复制了过来 (各位抱歉,由于之前上传的文件可能有错误,之前上传的文件PWM不能用,那么我又重新上传了一个文件,这个文件 ...

  2. java中System.out.println()打印输出结果

    疑点:syso()是打印输出语句,打印的是什么? syso()不同情况下打印输出的结果不一样: 1. package com.briup; public class Syso { public sta ...

  3. 转载:MyBatis mapper.xml中使用静态常量或者静态方法

    转自:https://my.oschina.net/wtslh/blog/682704 今天偶然之间刷到了这样一篇博客,有点意外 mybatis 还可以这样使用ONGL常量的方式,该方式针对 xml的 ...

  4. sqoop 密码别名模式 --password-alias

    sqoop要使用别名模式隐藏密码 1.首先使用命令创建别名 hadoop credential create xiaopengfei  -provider jceks://hdfs/user/pass ...

  5. 第四章 文件的基本管理和XFS文件系统备份恢复 随堂笔记

    第四章 文件的基本管理和XFS文件系统备份恢复 本节所讲内容: 4.1 Linux系统目录结构和相对/绝对路径. 4.2 创建/复制/删除文件,rm -rf / 意外事故 4.3 查看文件内容的命令 ...

  6. html的一些基本属性介绍

    一.html的属性类型: 1.常见标签属性: a.<h1>:align对其方式      例如:<h1  align="right"> hhhhh</ ...

  7. 【0806 | Day 9】三张图带你了解数据类型分类和Python深浅拷贝

    一.数据类型分类 二.Python深浅拷贝

  8. Spark 系列(十六)—— Spark Streaming 整合 Kafka

    一.版本说明 Spark 针对 Kafka 的不同版本,提供了两套整合方案:spark-streaming-kafka-0-8 和 spark-streaming-kafka-0-10,其主要区别如下 ...

  9. case when多条件

    SELECT label ,label3 ,lon_cen ,lat_cen ,lon3 ,lat3 ,antenna_height ,horizontal_angle ,CASE WHEN roun ...

  10. 简析 Golang net/http 包

    net/http 包涵盖了与 HTTP 请求发送和处理的相关代码.虽然包中定义了大量类型.函数,但最重要.最基础的概念只有两个:ServeMux 和 Handler. ServeMux 是 HTTP ...