HDU 3555 Bomb 数位DP 入门
给出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 入门的更多相关文章
- 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)
链接: https://vjudge.net/problem/HDU-3555 题意: The counter-terrorists found a time bomb in the dust. Bu ...
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- hdu3555 Bomb 数位DP入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3555 简单的数位DP入门题目 思路和hdu2089基本一样 直接贴代码了,代码里有详细的注释 代码: ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 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], ...
随机推荐
- Java继承_接口练习题
1.创建一个名称为StaticDemo的类,并声明一个静态变量和一个普通变量.对变量分别赋予10和5的初始值.在main()方法中输出变量值. 编写代码如下: package org.hanqi.pr ...
- 一些基本的C/C++数据类型
size_t size_t. A basic unsigned integer C/C++ type. It is the type of the result returned by sizeof ...
- Unity3D研究院编辑器之Editor的GUI的事件拦截
OnGUI是Unity上一个时代的UI系统,而现在运行时的UI系统已经被UGUI取代,但是Editor的UI还是在用老的这一套GUI系统.比如unity编辑器里的所有窗口,布局,按钮,拖动条.滚动等等 ...
- 掌握 Ajax,第 1 部分: Ajax 入门简介
转:http://www.ibm.com/developerworks/cn/xml/wa-ajaxintro1.html 掌握 Ajax,第 1 部分: Ajax 入门简介 理解 Ajax 及其工作 ...
- Python字典笔记
1.字典是Python中=唯一的映射类型.映射类型对象里哈希值(键,key)和只指向的对象(值,value)是一对多的关系,一个字典是可变的,是一个容器类型.字典类型和序列类型(元组,列表)的不同在于 ...
- c# 图片XML序列化与反序列化
var xmlDoc = new XmlDocument(); xmlDoc.Load(@"C:\Users\*\Desktop\*.xml"); ].ChildNodes[]; ...
- linq字符串搜索条件,排序条件-linq动态查询语句 Dynamic LINQ
在做搜索和排序的时候,往往是前台传过来的字符串做条件,参数的数量还不定,这就需要用拼sql语句一样拼linq语句.而linq语句又是强类型的,不能用字符串拼出来. 现在好了,有个开源的linq扩展方法 ...
- @include与jsp:include的区别
1.可以使用一个JSP指令或者一个标准行为,在JSP页面中引入其他的页面片段. 2. include指令:在翻译阶段(将JSP页面转换成servlet的阶段),JSP的include指令会读入指定的页 ...
- nginx windows 版 创建windows 服务
使用的工具 Windows Service Wrapper 使用的指令 nginx -s top Windows Service Wrapper 工具的使用: 1. 定义xml 文件: 说明如下: ...
- 无法启动:此实现不是Windows平台FIPS验证的加密算法的一部分
个别同学可能会在启动订票助手.NET的时候发现这个提示: 出现这个问题的原因是订票助手.NET使用了MD5算法,而系统的组策略安全设置导致无法使用此算法.要修正此问题,请按照如下操作(两种方法任选其一 ...