给出n,问所有[0,n]区间内的数中,不含有49的数的个数

数位dp,记忆化搜索

dfs(int pos,bool pre,bool flag,bool e)

pos:当前要枚举的位置

pre:当前要枚举的位置的前面是否为4

flag:枚举当前时,这个数的49时候被算过了

e:当前位置是否可以随便取值

dp[pos][pre][flag]

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> #define ull unsigned long long using namespace std; const int maxn=; ull dp[maxn][][];
int a[maxn]; ull solve(ull ); int main()
{
memset(dp,-,sizeof dp); //先初始化
int test;
cin>>test;
while(test--){
ull n;
cin>>n;
cout<<solve(n)<<endl;
}
return ;
} ull dfs(int pos,bool pre,bool flag,bool e)
{
if(!pos)
return flag; //不是返回0
if(e && dp[pos][pre][flag]!=-)
return dp[pos][pre][flag]; int last=e?:a[pos];
ull ret=;
for(int i=;i<=last;i++){
ret+=dfs(pos-,i==,flag||(pre&&i==),e||(!e&&i<last));
}
if(e)
dp[pos][pre][flag]=ret;
return ret;
} ull solve(ull n)
{
int len=;
while(n){
a[++len]=n%;
n/=;
}
return dfs(len,,,);
}

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)

    链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...

  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. hdu3555 Bomb 数位DP入门

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...

  5. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  6. HDU(3555),数位DP

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

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

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

  8. hud 3555 Bomb 数位dp

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

  9. hdoj 3555 BOMB(数位dp)

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

随机推荐

  1. 《灰帽Python-黑客和逆向工程师的Python编程》学习记录

    ctypes是Python语言的一个外部库,提供和C语言兼容的数据类型,可以很方便的调用C DLL中的函数. 操作环境:CentOS6.5 Python版本:2.66 ctypes是强大的,强大到本书 ...

  2. UVALive4287 hdu2767 hdu3836 强连通

    题意:有多个命题,需要证明他们可以互相推出,现在已经有一些证明关系即 A 可以证明 B,问至少还需要多少证明关系. 首先,如果某几个命题证明关系可以成环,那么这些命题必然可以相互证明,只要沿着环的边走 ...

  3. JS/JQuery控制图片宽度

    function changeImgWidth(){ for (i = 0; i <$('#info img').length; i++) { var imgWidth=$('#info img ...

  4. Android系统 小米/三星/索尼 应用启动图标未读消息数(BadgeNumber)动态提醒

    http://www.51itong.net/android-badgenumber-9789.html Android系统 小米/三星/索尼 应用启动图标未读消息数(BadgeNumber)动态提醒 ...

  5. PHP递归题目

    $arr = [ 'a' => 'A', 'b' => 'B', 'c' => [ 'd'=> 'D', 'e'=>[ 'f'=>'F', 'g'=>['h' ...

  6. 29个要点帮你完成java代码优化

    通过java代码规范来优化程序,优化内存使用情况,防止内存泄露 可供程序利用的资源(内存.CPU时间.网络带宽等)是有限的,优化的目的就是让程序用尽可能少的资源完成预定的任务.优化通常包含两方面的内容 ...

  7. ServiceStack

    https://github.com/ServiceStack/ServiceStack/wiki/Routing Service Gateway https://github.com/Service ...

  8. 机器学习&人工智能书籍

    Introduction to Machine Learning https://www.amazon.cn/Introduction-to-Machine-Learning-Alpaydin-Eth ...

  9. JSBinding + SharpKit / 原理篇:内存管理与垃圾回收

    C# 和 JS 都有垃圾回收机制,需要保证 2 者能够分工协作. 类对象 类在C#中是引用类型.我们在 C# 中维护了2个map,保存 C# 对象和 JS 对象的一一对应关系. 举一个例子,看以下代码 ...

  10. 动态链接库中函数的地址确定---PLT和GOT [转]

    前面写过动态链接库 延迟绑定的一篇博文,那篇文章我非常喜欢,但是当时刚搞清楚,自己写的比较凌乱,我最近学习了Ulrich Drepper的How to write share library,学习了几 ...