嘟嘟嘟




这题一看就是数位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. java——初识

    java是现在最火的高级编程语言之一,功能强,应用广. java可以做什么? 1. 开发桌面应用程序 2. 开发面向Internet的应用程序 开发java程序的基本步骤: 1. 编写源程序:mypr ...

  2. class example of C++

    #include <iostream> using namespace std; class Rectangle {     int width, height;   public:    ...

  3. python爬虫入门urllib库的使用

    urllib库的使用,非常简单. import urllib2 response = urllib2.urlopen("http://www.baidu.com") print r ...

  4. 如何实现JavaScript的Map和Filter函数?

    译者按: 鲁迅曾经说过,学习JavaScript最好方式莫过于敲代码了! 原文: Master Map & Filter, Javascript’s Most Powerful Array F ...

  5. JavaScript开发工具大全

    译者按: 最全的JavaScript开发工具列表,总有一款适合你! 原文: THE ULTIMATE LIST OF JAVASCRIPT TOOLS 译者: Fundebug 为了保证可读性,本文采 ...

  6. react children

    children react 中,属性名是一一对应的,除了children. 对于一个组件来说,其this.props.children拿到的是什么呢???举个

  7. js 做账单处理

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  8. C#:获取视频某一帧的缩略图

    读取方式:使用ffmpeg读取,所以需要先下载ffmpeg.网上资源有很多. 原理是通过ffmpeg执行一条命令获取视频某一帧的缩略图. 首先,需要获取视频的帧高度和帧宽度,这样获取的缩略图才不会变形 ...

  9. (后端)解决code唯一码(java)简便方法

    public String next() { long appBootTimes = systemVariableService.getAppBootTimes(); return Long.toSt ...

  10. Android Studio无线连调式android手机

    两种方法: 一.打开命令行或者Terminal窗口, 运行  adb connect 192.168.10.163:5555  来通过wifi连接手机调试 IP地址查看手机wifi的ip  要求手机和 ...