给出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. html5 input type=search

    <style> input[type="search"]{ border-radius:2px;} input::-webkit-search-cancel-butto ...

  2. http协议传输二进制数据以及对输入流(php://input)和http请求的理解

    1.index.php <?php $data=file_get_contents('./a.jpg'); $opts = array('http' => array( 'method' ...

  3. C#联调C++项目

    很多人在编写C#代码时,经常要调用C++代码,有时我们通常用打日志来查看运行状况,这当然可以,不过这样挺不方便,一遍遍的跑代码,一遍遍的看日志,感觉如果可以直接把断点打入C++的代码就好了,其实是可以 ...

  4. background-position 用法详细介绍

    语法: background-position : length || length background-position : position || position 取值: length  : ...

  5. IIS调用COM组件的权限问题

    在DCOM组件服务中给MICROSOFT.EXCEL组件 赋予ASP.NET的操作权限,具体步骤: (1)打开开始菜单的运行对话框,输入dcomcnfg命令,确定,这时会弹出组件服务窗口 (2)展开计 ...

  6. org.springframework.orm.hibernate3.support.OpenSessionInViewFilter作用

    在Spring与Hibernate集成时在web.xml要加入这样的过滤器: <filter> <filter-name>openSessionInView</filte ...

  7. 001. 使用ssh连接不上centos 6.5的解决方法及其解决中文乱码

    1. 使用ssh连接不上centos 6.5的解决方法: 错误显示: Connecting to 192.168.1.106:22... Could not connect to '192.168.1 ...

  8. OpenJudge计算概论-校门外的树

    /*======================================================================== 校门外的树 总时间限制: 1000ms 内存限制: ...

  9. python input() 与 raw_input()

    使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时: input返回的是数值类型,如int,floatraw_inpo ...

  10. java中的包装类与装箱拆箱定义

    JAVA 中int类型转String类型的通常方法,有三种:  1.String.valueOf(int i)  2.Integer.toString(int i)  3.i+"" ...