传送门

Luogu

解题思路

数位 \(\text{DP}\)

设状态 \(dp[now][las][0/1][0/1]\) 表示当前 \(\text{DP}\) 到第 \(i\) 位,前一个数是 \(las\),有没有顶到上界,有没有前导零的答案。

转移十分显然。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <vector>
#define rg register
using namespace std; template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
} const int _ = 11; int a[_], dp[_][_]; inline int dfs(int now, int las, int lim, int zero) {
if (now == 0) return 1;
if (!lim && !zero && dp[now][las] != -1) return dp[now][las];
int res = 0, tp = lim ? a[now] : 9;
for (rg int j = 0; j <= tp; ++j)
if (abs(j - las) >= 2) {
int _lim = lim && j == tp;
int _zero = zero && j == 0;
int _las = _zero ? -2 : j;
int _now = now - 1;
res += dfs(_now, _las, _lim, _zero);
}
if (!lim && !zero) dp[now][las] = res;
return res;
} inline int solve(int x) {
int n = 0;
for (rg int i = x; i; i /= 10) a[++n] = i % 10;
memset(dp, -1, sizeof dp);
return dfs(n, -2, 1, 1);
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
int l, r;
read(l), read(r);
printf("%d\n", solve(r) - solve(l - 1));
return 0;
}

完结撒花 \(qwq\)

「SCOI2009」windy数的更多相关文章

  1. 「FJOI2016」神秘数 解题报告

    「FJOI2016」神秘数 这题不sb,我挺sb的... 我连不带区间的都不会哇 考虑给你一个整数集,如何求这个神秘数 这有点像一个01背包,复杂度和值域有关.但是你发现01背包可以求出更多的东西,就 ...

  2. LibreOJ2095 - 「CQOI2015」选数

    Portal Description 给出\(n,k,L,R(\leq10^9)\),求从\([L,R]\)中选出\(n\)个可相同有顺序的数使得其gcd为\(k\)的方案数. Solution 记\ ...

  3. 「CQOI2015」选数

    「CQOI2015」选数 题目描述 我们知道,从区间[L,H](L和H为整数)中选取N个整数,总共有(H-L+1)^N种方案.小z很好奇这样选出的数的最大公约数的规律,他决定对每种方案选出的N个整数都 ...

  4. 【LOJ】#3094. 「BJOI2019」删数

    LOJ#3094. 「BJOI2019」删数 之前做atcoder做到过这个结论结果我忘了... em,就是\([1,n]\)之间每个数\(i\),然后\([i - cnt[i] + 1,i]\)可以 ...

  5. 「BZOJ3505」[CQOI2014] 数三角形

    「BZOJ3505」[CQOI2014] 数三角形 这道题直接求不好做,考虑容斥,首先选出3个点不考虑是否合法的方案数为$C_{(n+1)*(m+1)}^{3}$,然后减去三点一线的个数就好了.显然不 ...

  6. BZOJ 1026 【SCOI2009】 windy数

    Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? I ...

  7. 【BZOJ1026】【SCOI2009】windy数

    Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? In ...

  8. 【数位DP】【SCOI2009】windy数

    传送门 Description \(windy\)定义了一种\(windy\)数.不含前导零且相邻两个数字之差至少为\(2\)的正整数被称为\(windy\)数.\(windy\)想知道, 在\(A\ ...

  9. [SCOI2009] [BZOJ1026] windy数

    windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数?\(1 \le A \le ...

随机推荐

  1. ubuntu apache 通过端口新建多个站点

    cd /etc/apache2/sites-available 最近的虚拟机没绑定域名,所以呢,就先用域名加端口新建几个站点用着 1. vim /etc/apapche2/apapche2.conf ...

  2. cf--TV Subscriptions (Hard Version)

    time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standa ...

  3. ANSYS 瞬态热分析--样件加热

    目录 1. 要求 2. ANSYS有限元分析 2.1 APDL建模 1. 要求 一块0.8m*0.4m*0.2m厚的钢板,在300℃的炉子中进行加热,其材料参数如下表所示: 材料参数 序号 名称 参数 ...

  4. 【Python】【Django】用户注册功能

    GET方法前置步骤做完 stu.models.py 再其中创建需要用到的字段及对应数据库的表 # -*- coding: utf-8 -*- from __future__ import unicod ...

  5. Update(stage3):第1节 redis组件:8、主从复制架构;9、Sentinel架构

    8.redis的主从复制架构 在Redis中,用户可以通过执行SLAVEOF命令或者设置slaveof选项,让一个服务器去复制(replicate)另一个服务器,我们称呼被复制的服务器为主服务器(ma ...

  6. 树莓派4B踩坑指南 - (12)谷歌浏览器书签同步

    书签和插件不能同步真的是不方便..使用时删掉※符号 过程比较复杂,坑很多,但确认有效 免费访问说明: https://github.com/max2max/fre※es※s 软件安装 https:// ...

  7. video标签 在微信浏览器打开,不弹出大的独立窗口 而是直接播放。

    1.在 video 标签中添加   属性    x5-playsinline  playsinline  webkit-playsinline="true" 2.ckplayer的 ...

  8. ES 创建mapping

    mapping的写入与查看首先创建一个索引: curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{&q ...

  9. opencv人脸识别提取手机相册内人物充当数据集,身份识别学习(草稿)

    未写完 采用C++,opencv+opencv contrib 4.1.0 对手机相册内人物opencv人脸识别,身份识别学习 最近事情多,介绍就先不介绍了 photocut.c #include & ...

  10. centos610无桌面安装libreoffice缺失字体

    1.安装libreoffice 2.安装fontconfig yum -y install fontconfig 3.安装ttmkfdir yum -y install ttmkfdir 4.检查已有 ...