[洛谷P4124][CQOI2016]手机号码
题目大意:给你两个$l,r$,求出$[l,r]$中符合要求的数,要求为至少有$3$个相邻的相同数字,且不可以同时出现$8$和$4$
题解:数位$DP$
卡点:无
C++ Code:
#include <cstdio>
#include <algorithm>
long long l, r;
int num[13], tot;
long long f[13][4][2][2][11];
long long calc(int x, int lim, int lead, int had48, int len3, int len2, int lst) {
if (had48 == 3) return 0;
if (!x) return len3;
long long F = f[x][had48][len3][len2][lst];
if (!lim && lead && ~F) return F;
F = 0;
for (int i = lim ? num[x] : 9, op = 1; i + lead; i--, op = 0) {
int __had48 = had48;
if (i == 4) __had48 |= 1;
if (i == 8) __had48 |= 2;
F += calc(x - 1, op && lim, lead || i, __had48, len3 | (len2 && (lst == i)), lst == i, i);
}
if (!lim && lead) f[x][had48][len3][len2][lst] = F;
return F;
}
long long solve(long long x) {
if (x < 10000000000) return 0;
tot = 0;
while (x) {
num[++tot] = x % 10;
x /= 10;
}
return calc(tot, 1, 0, 0, 0, 0, 10);
}
int main() {
scanf("%lld%lld", &l, &r);
__builtin_memset(f, -1, sizeof f);
printf("%lld\n", solve(r) - solve(l - 1));
return 0;
}
[洛谷P4124][CQOI2016]手机号码的更多相关文章
- 洛谷 P4124 [CQOI2016]手机号码
题意简述 求l~r之间不含前导零,至少有三个相邻的相同数字,不同时含有4和8的11位正整数的个数 题解思路 数位DP,注意在l,r位数不够时补至11位 代码 #include <cstdio&g ...
- [Luogu P4124] [CQOI2016]手机号码 (数位DP)
题面 传送门:洛咕 Solution 感谢神仙@lizbaka的教学 这题是数位DP的非常非常模板的题目,只是状态有点多 . 这题我使用记忆化搜索实现的 中国有句古话说的好,有多少个要求就设多少个状态 ...
- 洛谷 P4124 (数位 DP)
### 洛谷 P4124 题目链接 ### 题目大意: 给你一段区间,让你求满足下列两个条件时的数的个数. 1.至少有 3 个相邻相同数字 (即 111 .1111 .222 等) 2.不能同时出现 ...
- P4124 [CQOI2016]手机号码
P4124 [CQOI2016]手机号码 题解 数位DP DFS 虽然套路,但还是恶心到找不到锅在哪里 注意这个 然后你就发现其实这样就不用记录前导0了 锅在这个鬼地方QAQ 代码 #inclu ...
- 【洛谷P4124】[CQOI2016]手机号码
手机号码 数位DP模板题 记忆化搜索: #include<iostream> #include<cstring> #include<cstdio> using na ...
- 洛谷P4124 手机号码
传送 这题也就是条件限制多了点,也没有别的,套板子就好了 注意这里没有前导零,所以第一位是从1开始填 看注释叭 #include<iostream> #include<cstdio& ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
随机推荐
- 【PHP项目】产品新增的多图上传
产品新增:多图上传 1:html的更改 在 type=file的input框中添加multiple="multiple" name属性中必须添加[] ,否则$_FILES只能接收最 ...
- Python学习之模块基础
模块就是程序 编写以下简单代码 print('hello python') 并将py文件保存在c盘的python(假设新建)文件下,通过pycharm的Terminal 或者windom命令窗口调出p ...
- 分享一个根据具体的日期判断星座的PHP函数
其实原理很简单,也就是把所有的星座月份日期范围存储到一个数组中,然后根据日期判断属于哪个范围,这样就得到是哪个星座了. 下面的这个函数写的比较精炼,可以参考一下 function constellat ...
- mongodb的学习之旅一
描述 作为一枚菜鸟级别的coder,刚接触nodejs没有多久.现在在学习微信公众号的开发,但是碰到了mongodb保存用户数据的时候,出现了DeprecationWarning: Mongoose: ...
- node解析post表单信息
一共有4种解析方式 urlencoded.json.text .raw 发起请求的form表单中可以设置三种数据编码方式 application/x-www-form-urlencoded.multi ...
- cf776D Mahmoud and a Dictionary
Mahmoud wants to write a new dictionary that contains n words and relations between them. There are ...
- [Cracking the Coding Interview] 4.3 List of Depths
Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth. ...
- xssbypass小记
简单整理下bypass的一些点 标签外 如果是标签之外 又有htmlspecialchars函数的点 就别想了 在标签外同时能xss但是有长度限制 如果是储存型可以利用多个点 然后构造<scri ...
- 什么是 Cookie
什么是 Cookie? Cookie 是一小段文本信息,伴随着用户请求和页面在 Web 服务器和浏览器之间传递.Cookie 包含每次用户访问站点时 Web 应用程序都可以读取的信息. 例如,如果在用 ...
- struts2官方 中文教程 系列十四:主题Theme
介绍 当您使用一个Struts 2标签时,例如 <s:select ..../> 在您的web页面中,Struts 2框架会生成HTML,它会显示外观并控制select控件的布局.样式和 ...