嘟嘟嘟




这题一看就是数位dp。

我写数位dp,一般是按数位dp的格式写一个爆搜,然后加一点记忆化。

不过其实我一直不是很清楚记忆化是怎么加,感觉就是把dfs里的参数都扔到dp数组里,好像很暴力啊。

这题有一个坑点就是数字必须是电话号码,也就是11位且没有前导零。因此关于前导零的处理是最高位不能为0,剩下的都可以。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
//const int maxn = ;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int num[15], cnt = 0;
ll dp[15][10][10][2][2][2][2];
In ll dfs(int now, int pre1, int pre2, bool _lian, bool _4, bool _8, bool _zero, bool _Max)
{
if(_4 && _8) return 0;
if(!now) return _lian;
if(~pre1 && ~pre2 && ~dp[now][pre1][pre2][_lian][_4][_8][_Max]) return dp[now][pre1][pre2][_lian][_4][_8][_Max];
int Min = _zero ? 1 : 0, Max = _Max ? num[now] : 9;
ll ret = 0;
for(int i = Min; i <= Max; ++i)
ret += dfs(now - 1, i, pre1, _lian || (i == pre1 && i == pre2), _4 || (i == 4), _8 || (i == 8), _zero && !i, _Max && i == Max);
if(~pre1 && ~pre2) dp[now][pre1][pre2][_lian][_4][_8][_Max] = ret;
return ret;
}
In ll solve(ll n)
{
cnt = 0;
while(n) num[++cnt] = n % 10, n /= 10;
if(cnt < 11) return 0;
Mem(dp, -1);
return dfs(cnt, -1, -1, 0, 0, 0, 1, 1);
} int main()
{
ll l = read(), r = read();
write(solve(r) - solve(l - 1)), enter;
return 0;
}

[CQOI2016]手机号码的更多相关文章

  1. 4521: [Cqoi2016]手机号码

    4521: [Cqoi2016]手机号码 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 1030 Solved: 609 [Submit][Statu ...

  2. [BZOJ4521][CQOI2016]手机号码(数位DP)

    4521: [Cqoi2016]手机号码 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 875  Solved: 507[Submit][Status ...

  3. [Bzoj4521][Cqoi2016]手机号码(数位dp)

    4521: [Cqoi2016]手机号码 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 870  Solved: 505[Submit][Status ...

  4. [CQOI2016]手机号码 数位DP

    [CQOI2016]手机号码 用来数位DP入门,数位DP把当前是否需要限制取数范围(是否正在贴着临界值跑,即下面的limited)和一切需要满足的条件全部塞进记忆化搜索参数里面就好了,具体情况转移便好 ...

  5. P4124 [CQOI2016]手机号码

    P4124 [CQOI2016]手机号码 题解 数位DP   DFS  虽然套路,但还是恶心到找不到锅在哪里 注意这个 然后你就发现其实这样就不用记录前导0了 锅在这个鬼地方QAQ 代码 #inclu ...

  6. [Luogu P4124] [CQOI2016]手机号码 (数位DP)

    题面 传送门:洛咕 Solution 感谢神仙@lizbaka的教学 这题是数位DP的非常非常模板的题目,只是状态有点多 . 这题我使用记忆化搜索实现的 中国有句古话说的好,有多少个要求就设多少个状态 ...

  7. BZOJ4521: [Cqoi2016]手机号码

    Description 人们选择手机号码时都希望号码好记.吉利.比如号码中含有几位相邻的相同数字.不含谐音不 吉利的数字等.手机运营商在发行新号码时也会考虑这些因素,从号段中选取含有某些特征的号 码单 ...

  8. BZOJ4521 Cqoi2016 手机号码 【数位DP】

    Description 人们选择手机号码时都希望号码好记.吉利.比如号码中含有几位相邻的相同数字.不含谐音不吉利的数字等.手机运营商在发行新号码时也会考虑这些因素,从号段中选取含有某些特征的号码单独出 ...

  9. 【洛谷P4124】[CQOI2016]手机号码

    手机号码 数位DP模板题 记忆化搜索: #include<iostream> #include<cstring> #include<cstdio> using na ...

  10. [BZOJ4521][Cqoi2016]手机号码 (数位dp)

    题目描述 人们选择手机号码时都希望号码好记.吉利.比如号码中含有几位相邻的相同数字.不含谐音不吉利的数字等.手机运营商在发行新号码时也会考虑这些因素,从号段中选取含有某些特征的号码单独出售.为了便于前 ...

随机推荐

  1. VM扩展磁盘大小

    1.通过扩展磁盘的方法增大磁盘大小 2.然后开启Linux 此时查看磁盘  df -h 并没有增加,使用 fdisk -l 查看发现已经扩展 使用 root 用户,进入到 ~ 家目录下面. 3.使用 ...

  2. CSS基础知识思维导图xmind

    这是我根据自己的学习笔记整理的思维导图,WEB前端的知识很多,汇总来看会比较清晰.

  3. express入门

    (1)express的安装 $ npm install express 或者 $ npm install -g express 或者 $ npm install express -gd 备注: -g ...

  4. 09-HTML-form标签

    <html> <head>  <title>form标签学习</title>  <meta charset="utf-8"/& ...

  5. 用webpack2.0构建vue2.0超详细精简版

    初始化环境 npm init -y 初始化项目 安装各种依赖项 npm install --save vue 安装vue2.0 npm install --save-dev webpack@^2.1. ...

  6. 洛谷P5205 【模板】多项式开根(多项式sqrt)

    题意 题目链接 Sol 这个就很没意思了 求个ln,然后系数除以2,然后exp回去. #include<bits/stdc++.h> #define Pair pair<int, i ...

  7. 洛谷P4588 [TJOI2018]数学计算(线段树)

    题意 题目链接 Sol TJOI怎么全是板子题 对时间开个线段树,然后就随便做了.... #include<bits/stdc++.h> using namespace std; cons ...

  8. mysql安装完成之后为root用户添加密码

    编辑MySql的配置文件:my.ini(在MySql安装目录下). 打开配置文件,在文件最后一行添加:skip-grant-tables,然后保存退出. 意思为就是在启mysql时不启动grant-t ...

  9. C#字典Dictionay多线程读是否是安全的

    答案:是线程安全的,只读不写多线程下,完全不需要加锁! 测试代码: using System; using System.Diagnostics; using System.Threading; us ...

  10. 四. Redis事务处理

    Redis目前对事务的支持还是比较简单,Redis能保证一个Client发起的事务中的命令可以连续执行,而中间不会插入其他Client的命令:当一个Client在连接中发起一个multi命令的时候,这 ...