链接:

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)的更多相关文章

  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. Bomb HDU - 3555 (数位DP)

    Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...

  4. HDU(3555),数位DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others ...

  5. HDU 3555 Bomb (数位DP-记忆化搜索模板)

    题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...

  6. hud 3555 Bomb 数位dp

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Subm ...

  7. hdoj 3555 BOMB(数位dp)

    //hdoj 3555 //2013-06-27-16.53 #include <stdio.h> #include <string.h> __int64 dp[21][3], ...

  8. 数位DP入门之hdu 3555 Bomb

    hdu 3555 Bomb 题意: 在1~N(1<=N<=2^63-1)范围内找出含有 ‘49’的数的个数: 与hdu 2089 不要62的区别:2089是找不不含 '4'和 '62'的区 ...

  9. HDU 3555 Bomb(数位DP模板啊两种形式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 Problem Description The counter-terrorists found ...

随机推荐

  1. Django-02-django的命令行工具

    django-admin.py 是Django的一个用于管理任务的命令行工具,manage.py是对django-admin.py的简单包装,每一个Django Project里都会有一个mannag ...

  2. 34 多线程(六)——线程安全 synchronized

    关键字synchronized可以写在方法和代码块中 写在普通方法中:锁住的对象是this,即类的实例.也就是说锁住的是类下面的类变量(成员变量),而不是方法中的变量. 写在静态方法中:锁住的对象时c ...

  3. python3+requests:post请求四种传送正文方式

    https://www.cnblogs.com/insane-Mr-Li/p/9145152.html 前言:post请求我在python接口自动化2-发送post请求详解(二)已经讲过一部分了,主要 ...

  4. [CF896C]Willem, Chtholly and Seniorious

    题目大意:有$n$个数,有$m$次$4$种操作: l r x :将$[l,r]$区间所有数加上$x$ l r x :将$[l,r]$区间所有数变成$x$ l r k :输出$[l,r]$区间第$k$大 ...

  5. 测试PHP-FPM的工作流中的疑惑点

    顺序比较乱,想到什么测试什么,测试环境 PHP7.2 和 MariaDB10.3.11 PHP-FPM是 master/worker 多进程模型master负责和web-server通讯,把接受到请求 ...

  6. vue 项目之后生成的 dist 文件该怎么在本地启动运行

    简单高效 npm i -g servecd distserve

  7. Disruptor底层源码解析(九)

    架构图: 性能为什么这么牛逼: public void sendData(ByteBuffer data) { //1 在生产者发送消息的时候, 首先 需要从我们的ringBuffer里面 获取一个可 ...

  8. asp.net WEB简单打印

    ASP.NET网页打印 2018.08.26 18:50 1096浏览   昨晚朋友要求在前段时间完成的新闻的网站上加上一个功能,就是在每篇新闻浏览的页面, 加一个打印铵钮.让用户一点打印,能把整篇文 ...

  9. power shell命令添加SharePoint用户组与用户(用户为域用户)

    查看SharePoint用户组 Get-PnPGroup 查看某一用户组 Get-PnPGroup -Identity "用户组名" 查看某一用户组下的所有成员 Get-PnPGr ...

  10. js(es6)数组去重

    // 利用set.reduce.filter去重 // Set function getSetArr(arr) { return [...new Set(arr)] } console.log(get ...