hdu 3555 Bomb(数位dp入门)
Bomb
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 24148 Accepted Submission(s): 9092
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
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
int bit[40];
ll f[40][3];
ll dp(int pos,int st,bool flag)
{
if(pos==0)return st==2;
if(flag&&f[pos][st]!=-1)return f[pos][st];
ll ans=0;
int x=flag?9:bit[pos];
for(int i=0;i<=x;i++)
{
if((st==2)||(st==1&&i==9))
{
ans+=dp(pos-1,2,flag||i<x);
}
else if(i==4)ans+=dp(pos-1,1,flag||i<x);
else ans+=dp(pos-1,0,flag||i<x);
}
if(flag)f[pos][st]=ans;
return ans;
}
ll calc(ll x)
{
int len=0;
while(x)
{
bit[++len]=x%10;
x/=10;
}
return dp(len,0,0);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int t;
scanf("%d",&t);
while(t--)
{
memset(f,-1,sizeof(f));
ll n;
scanf("%lld",&n);
printf("%lld\n",calc(n));
}
return 0;
}
hdu 3555 Bomb(数位dp入门)的更多相关文章
- HDU 3555 Bomb 数位DP 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- HDU 3555 Bomb 数位dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU - 3555 - Bomb(数位DP)
链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- HDU(3555),数位DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...
- HDU 3555 Bomb (数位DP-记忆化搜索模板)
题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...
- hud 3555 Bomb 数位dp
Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Subm ...
- hdoj 3555 BOMB(数位dp)
//hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...
随机推荐
- 20190724-Python网络数据采集/第 2 章 复杂HTML解析-导航树/正则表达式
1. 导航树 经典的HTML树状结构 直接看下面的代码示例:(注意目标网页的标签大小写等细节,易出bug) from urllib.request import urlopen from bs4 im ...
- 【第一季】CH09_FPGA多路分频器设计
[第一季]CH09_FPGA多路分频器设计 在第七节的学习中,笔者带大家通过一个入门必学的流水灯实验实现,快速掌握了VIVADO基于FPGA开发板的基本流程.考虑到很多初学者并没有掌握好Vivado ...
- java对象序列化并存储到文件中
● 如何将一个Java对象序列化到文件里 使用输入输出流,,一个是ObjectOutputStream 对象,ObjectOutputStream 负责向指定的流中写入序列化的对象.当从文件中读取序列 ...
- SIP中第三方呼叫控制(3PCC)建立流程
1.引言 在传统的电话网环境中,第三方呼叫控制允许一个实体(这里称为控制器- controller) 建立并管理另外的两方或多方之间的通信关系,而其本身并不参与通信. 第三方呼叫控制经常用于运营商业务 ...
- Makefile中 -I -L -l区别
我们用gcc编译程序时,可能会用到"-I"(大写i),"-L"(大写l),"-l"(小写l)等参数,下面做个记录: 例: gcc -o he ...
- EF Core的级联删除
级联删除由DeleteBehavior的枚举值来设置: 行为名称 对内存中的依赖项/子项的影响 对数据库中的依赖项/子项的影响 Cascade 删除实体 删除实体 ClientSetNull 外键属性 ...
- cmder 增强型命令行工具
下载 https://github.com/cmderdev/cmder/releases/download/1.3.13/cmder.zip Cmder加到右键菜单 https://www.jian ...
- 浅谈Promise原理与应用
在JavaScript中,所有代码都是单线程.由于该“缺陷”,JavaScript在处理网络操作.事件操作时都是需要进行异步执行的.AJAX就是一个典型的异步操作 对于异步操作,有传统的利用回调函数和 ...
- html5中本地存储概念是什么?
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage.sessionStorage用于本地存储一个会话中的数据,这些数据只有在同一个会话中的页 ...
- Android Stdio部分配置
一.Error:Cause: unable to find valid certification path to requested target主要是在根目录的build.gradle下配置的jc ...