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 ...
随机推荐
- Mysql中MVCC的使用及原理详解
准备 测试环境:Mysql 5.7.20-log 数据库默认隔离级别:RR(Repeatable Read,可重复读),MVCC主要适用于Mysql的RC,RR隔离级别 创建一张存储引擎为test ...
- jenkins配合dockerfile部署项目
前言 本节需要对jenkinsfile有点了解,对dockerfile有点了解,对shell有点了解,对docker有点了解 执行流程 jenkins拉取代码仓库中的代码 jenkins执行jenki ...
- (四)pdf的构成之文件体(树图)
pdf的文件体类似于一个大树 有个根对象(catalog),该对象中保存着PDF的很多基本信息,并通过间接引用,辐射到所有的间接对象. (下图是大概的树形状)
- tkinter学习笔记_06
12.弹窗 messagebox import tkinter as tk from tkinter import messagebox root = tk.Tk() root.title(" ...
- gitlab-runner 的 executors 之 docker
gitlab-runner 的 executors 之 docker GitLab Runner 实现了许多执行程序,可用于在不同的场景中运行构建.所有执行程序分别为: SSH Shell Paral ...
- javascript 同源策略和 JSONP 的工作原理
同源策略 同源策略是一个约定,该约定阻止当前脚本获取或操作另一域的内容.同源是指:域名.协议.端口号都相同. 简单地说,A 服务器下的 a 端口执行 ajax 程序,不能获取 B 服务器或者 A 服务 ...
- ubuntu 迅雷 XwareDesktop
Xinkai/XwareDesktop Ubuntu上编译安装说明 Home Ubuntu上编译安装说明 使用说明 升级到0.12 升级到0.9 发行版支持情况 名 ...
- 阿里云ssl协议发布qq邮件
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...
- JavaScript:将key和value不带双引号的JSON字符串转换成JSON对象的方法
遇到相关的问题,花了两天的时间来解决,深感来之不易,所以做如下的总结,希望遇到此问题的码农能更快的找到解决办法! var jsonArr= [{col:TO_CHAR(HZRQ,'YYYYMM'),t ...
- c#测量字体宽度
Bitmap image_size = * count, f.Height);//初始化大小 Graphics size_g = Graphics.FromImage(image_size); Siz ...