HDU - 2089 数位DP 初步
中文题目,不要62和4
从高位往低位DP,注意有界标志limit的传递
dp2记忆有界情况下的计数结果,据说用处不大
我所参考的入门文章就是半搜索(有界)半记忆(无界)的
进阶指南中提出dfs维度有多少那么dp维度就是多少,因此原文的pre确实是没用的
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e3+11;
const double eps = 1e-10;
typedef long long ll;
const int oo = 0x3f3f3f3f;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll dp[maxn][2],a[maxn],l,r;
ll dp2[maxn][2];
ll DP(int cur,bool _6,bool limit){
if(cur==0) return 1;
if(dp[cur][_6]!=-1&&!limit)return dp[cur][_6];
if(dp2[cur][_6]!=-1&&limit)return dp2[cur][_6];
int up=(limit?a[cur]:9);
ll ans=0;
rep(i,0,up){
if(i==4)continue;
if(i==2&&_6)continue;
ans+=DP(cur-1,i==6,limit&&a[cur]==i);
}
return limit?dp2[cur][_6]=ans:(dp[cur][_6]=ans);
}
ll solve(ll num){
memset(a,0,sizeof a);
memset(dp,-1,sizeof dp);
memset(dp2,-1,sizeof dp2);
int cur=0;
while(num){
a[++cur]=num%10;
num/=10;
}
return DP(cur,0,1);
}
int main(){
while(cin>>l>>r){
if(l==0&&r==0)break;
println(solve(r)-solve(l-1));
}
return 0;
}
HDU - 2089 数位DP 初步的更多相关文章
- hdu:2089 ( 数位dp入门+模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...
- HDU 2089 数位dp入门
开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...
- HDU 2089 数位dp/字符串处理 两种方法
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 2089 数位dp
链接:https://vjudge.net/problem/23625/origin 中文,题目不用说了. 其实这题的数据很小,所以直接暴力也可以过,但是还是要学会数位dp,因为并不是每一题的数据都会 ...
- 不要62(HDU 2089数位dp入门)
题意:统计区间 [a,b] 中不含 4 和 62 的数字有多少个. 分析:dp[i][f]数字表示不含 4 和 62的前提下,剩余长度为 len ,首位是否为 6 的个数. #include < ...
- 杭电hdu 2089 数位dp
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍 ...
- hdu 2089 数位dp入门题
#include<stdio.h> //dp[i][0]代表不存在不吉利数字 //dp[i][1]代表不存在不吉利数字但是以2开头 //dp[i][2]代表存在不吉利数字 #define ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- ROS 不能安装 Ros Packages
我的linux版本是16.04,安装的是kinetic 1. E: Some index files failed to download. They have been ignored, or ol ...
- 基于 EntityFramework 的数据库主从读写分离架构(1) - 原理概述和基本功能实现
回到目录,完整代码请查看(https://github.com/cjw0511/NDF.Infrastructure)中的目录: src\ NDF.Data.EntityFramew ...
- c语言实践 1/1+1/2+1/3+1/4+...+1/n
给定一个n求这个分式的和. int n = 1; float sum = 0; float frac = 0; int i = 1; scanf_s("%d",&n); w ...
- python学习资料资源
廖雪峰python教程: http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000 简明py ...
- docker入门及安装
Docker简介 Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机).ba ...
- word 2013如何从某一页开始插入页码
把光标移入要插入页面的最前面 插入分页符 在要插入页码的页脚双击打开页脚设计 取消页脚和前面页眉的链接 插入页码
- C++初始化,之不明白篇 cout<<x<<endl 与 cout<<"x = "<<cout<<x<<endl的输出的值会不一样
代码如下 #include <iostream> using namespace std; class point { public : int x; int y; ...
- Sobel算法
最近看了一些Sobel算法,并试了一下,源码如下: private void Sobel(Bitmap img) { int width = img.Width; int height = img.H ...
- Dapper ORM
参考地址:https://www.cnblogs.com/lunawzh/p/6607116.html 1.连接语句 var conn = new SqlConnection(Configuratio ...
- Eclipse内存不足 增加eclipse的运行内存
自己解决的 三. 修改Run Configurations (此方法可行) 在代码上右键,依次点击“Run As ”-> “Run Configurations ”,在Arguments ...