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. Java虚拟机学习笔记(一)之初识

    一:特定 跨平台性.安全性.可移植性. 二:体系机构 Java 体系结构包括四个独立但相关的技术: Java程序设计语言 Java Class文件格式 Java 应用编程接口(API) Java 虚拟 ...

  2. 【有容云】PPT | 容器落地之二三事儿

    编者注: 本文为10月29日有容云联合创始人兼研发副总裁江松在 Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一 ...

  3. Java悲观锁Pessimistic-Lock常用实现场景

    1:商品库存秒杀采用悲观锁Pessimistic-Lock主要好处是安全,充分利用了数据库的性能来做的一种锁机制. 悲观锁的实现: (1)环境:mysql + jdbctemplate (2)商品表g ...

  4. npm包开发与发布

    把通用的功能开发成npm包,便用使用和维护,更重要的是可以分享给广大的开发者,是不是很激动人心! 那么,步骤如下: 1.创建项目 创建项目目录,npm init ,根据需要输入配置信息(建完后也可以在 ...

  5. [Short-Circuit Constraint Violation]警告解决办法

    今天用Altium Designer16画PCB时候遇到一个问题,进行DRC检测,警告如下: [Short-Circuit Constraint Violation] GrayscaleSensor1 ...

  6. React 基于antd+video.js实现m3u8格式视频播放及实时切换

    文档连接地址(官网看起麻烦,看中文别人整理好的)https://blog.csdn.net/a0405221/article/details/80923090 React项目使用  安装依赖 npm ...

  7. WebService—— IDEA创建WebServices

    一.File–>New–>Project 弹出这个对话框后,照下图的勾选然后点击Next,然后填写项目名和项目路径后,点击finish. 二.生成目录如下 需要注意的有HelloWorld ...

  8. Spring 2017 Assignments1

    一.作业要求 原版:http://cs231n.github.io/assignments2017/assignment1/ 翻译:http://www.mooc.ai/course/268/lear ...

  9. Day4 chart基本属性分析

    属性设置是基于chart实例的,所以我们必须先获取一个chart画板实例,获取方式: G2.Chart.创建 Chart 的方式如下: new G2.Chart({ container: {strin ...

  10. linux细节操作的

    一>安装mysql 可以直接在linux系统下载 下载之前要安装wget插件 下载命令 wget 后面跟安装软件的url 比如mysql wget http://repo.mysql.com/m ...