HDU - 3555 - Bomb(数位DP)
链接:
https://vjudge.net/problem/HDU-3555
题意:
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?
思路:
考虑没有49的数,用a-掉就行。
Dp(i, j)
i位置为j时的值。
因为计算了0要多加1.
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10;
LL Dp[25][10];
int dig[25];
LL a;
LL Dfs(int pos, int pre, int zer, int lim)
{
if (pos == -1)
return 1;
if (!lim && Dp[pos][pre] != -1)
return Dp[pos][pre];
int up = lim ? dig[pos] : 9;
LL cnt = 0;
for (int i = 0;i <= up;i++)
{
if (pre == 4 && i == 9)
continue;
cnt += Dfs(pos-1, i, zer && i == 0, lim && i == up);
}
if (!lim)
Dp[pos][pre] = cnt;
return cnt;
}
LL Solve(LL x)
{
int p = 0;
while(x)
{
dig[p++] = x%10;
x /= 10;
}
return Dfs(p-1, -1, 1, 1);
}
int main()
{
// freopen("test.in", "r", stdin);
int t;
scanf("%d", &t);
memset(Dp, -1, sizeof(Dp));
while(t--)
{
scanf("%lld", &a);
printf("%lld\n", a-Solve(a)+1);
}
return 0;
}
HDU - 3555 - Bomb(数位DP)的更多相关文章
- 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 入门
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要 ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- 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], ...
- 数位DP入门之hdu 3555 Bomb
hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...
- HDU 3555 Bomb(数位DP模板啊两种形式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...
随机推荐
- Linux中的13个基本Cat命令示例
cat(“ concatenate ”的缩写)命令是Linux / Unix等操作系统中最常用的命令之一.cat命令允许我们创建单个或多个文件,查看文件包含,连接文件以及在终端或文件中重定向输出.在本 ...
- 函数的学习1——定义函数&传递实参——参考Python编程从入门到实践
定义函数 def greet_user(): print("Hello") greet_user() # PEP8 函数和类的定义后空两行 1. 向函数传递参数 def greet ...
- python3的 基础
]print(list(set(lst))) # 面试题: # a = 10 # b = 20 # a,b = b,a # 10000% # print(b) # 10 # print(a ...
- Linux删除含有特殊符号文件名的文件
1. 文件名含有特殊字符,直接使用 rm 可能删除不了,可以使用如下方法: 1) 使用 ls -i 查处该文件的 inode 号,假设为123 2) 使用find命令删除: rm `find . ...
- 协议——UART(RS232)
一.UART简介 UART(universal asynchronous receiver-transmitter)是一种采用异步串行通信方式的通用异步收发传输器.一般来说,UART总是和RS232成 ...
- ICO学习说明
IOC叫做控制反转,可以理解为我要做一件事,分为1,2,3,4这4部,我们可以在一个函数实现这四步,控制反转就是将这个流程体现在框架中.将原来实现在应用程序流程控制转移到框架中,框架利用一个引擎驱动整 ...
- 【OO学习】OO第四单元作业总结及OO课程总结
[OO学习]OO第四单元作业总结及OO课程总结 第四单元作业架构设计 第十三次作业 第十四次作业 总结 这两次作业架构思路上是一样的. 通过将需要使用的UmlElement,封装成Element的子类 ...
- dubbo源码阅读之负载均衡
负载均衡 在之前集群的文章中,我们分析了通过监听注册中心可以获取到多个服务提供者,并创建多个Invoker,然后通过集群类如FailoverClusterInvoker将多个Invoker封装在一起, ...
- Hive的五个基础介绍
一.什么是Hive? 1.Hive是一个翻译器,SQL ---> Hive引擎 ---> MR程序 2.Hive是构建在HDFS上的一个数据仓库(Data Warehouse) Hive ...
- antd-table——内容展示变型
bug单: https://github.com/ant-design/ant-design/issues/13825 1.设置固定宽度:在columns中设置widht或者className { t ...