给出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. PgSQL · 特性分析 · 谈谈checkpoint的调度

    在PG的众多参数中,参数checkpoint相关的几个参数颇为神秘.这些参数与checkpoint的调度有关,对系统的稳定性还是比较重要的,下面我们为大家解析一下,这要先从PG的数据同步机制谈起. P ...

  2. Comparison of B-Tree and Hash Indexes

    Understanding the B-tree and hash data structures can help predict how different queries perform on ...

  3. wikioi 1012最大公约数和最小公倍数【根据最大公约数和最小公倍数求原来的两个数a、b】

    /*====================================================================== 题目描述 输入二个正整数x0,y0(2<=x0& ...

  4. pouchdb sync

    PouchDB and CouchDB were designed for one main purpose: sync. Jason Smith has a great quote about th ...

  5. 【转】关于PHP的header("P3P: CP=CURa……")

    对于IE来说(默认安全级别下),iframe.img.link等标签都是只发送session cookie(又叫 第一方cookie),拦截本地cookie发送(又叫第三方cookie).当这些标签跨 ...

  6. JS刷新页面的几种方法(转)

    Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(locat ...

  7. 如何处理JSON数据中含有双引号

    {"quality": "B"A"D"} 实际上要 value.replace("\"","\\\& ...

  8. ubuntu设置环境变量

    sudo gedit /etc/environment path结尾处追加 路径,如::/opt/EmbedSky/4.3.3/bin source /etc/environment,或者重启电脑?? ...

  9. eclipse debug小技巧

    测试 Expressions 代码 public static void main(String[] args) { int x=100; System.out.println("----& ...

  10. 关于SqlServer的DBHelper类以及数据分页

    前端: <My:AspNetPager class="arPage" PageSize="20" UrlPaging="true" r ...