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 ...
随机推荐
- liunx mysql数据库目录迁移
1.查看mysql安装目录 从目录etc/my.cnf中查看安装目录 2.进入mysql目录,停止mysql服务 命令: cd usr/local/mysql 命令:service mysql sto ...
- LeetCode | 142. 环形链表 II
原题(Medium): 给定一个链表,返回链表开始入环的第一个节点. 如果链表无环,则返回 null. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始) ...
- python3.7 pip升级或安装,拒绝访问 解决方案
- win server 检查是否是ntfs文件系统
fsutil fsinfo volumeinfo c: | findstr /i "文件系统名"
- Jenkins + GitLab + SpringBoot 实现持续集成脚本
Linux脚本 #!/bin/bash jar_name=hq-api.jar cd /usr/local/app/hq-api echo "Stopping SpringBoot Appl ...
- git 学习笔记 ---远程仓库
Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上.怎么分布呢?最早,肯定只有一台机器有一个原始版本库,此后,别的机器可以“克隆”这个原始版本库,而且每台机器的版本库其实都是一样的, ...
- zipkin的安装与搭建
下载与部署 jar中yaml文件配置 启动传入并参数 web界面 目录 zipkin是分布式链路调用监控系统,聚合各业务系统调用延迟数据,达到链路调用监控跟踪. 下载与部署 wget -O zipki ...
- mysql数据库备份之主从同步配置
主从同步意义? 主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave).因为复制是异步进行的,所以从服务 ...
- Python接口自动化基础---post请求
常见的post传递参数的类型有以下两种: 第一种:application/x-www-form-urlencoded,浏览器原生的form表单,格式如下:input1=xxx&input2=o ...
- Mybatis中三种关联关系的实现
目录 一对一查询 一对多查询 自关联查询: 多对多查询 总结: 三种关联关系:一对多,一对一,多对多 两种查询方式:嵌套查询,连接查询(也可称作:多表单独查询,多表连接查询) 每一种关联关系都可以通过 ...