BZOJ原题链接

洛谷原题链接

简单的数位\(DP\),套模板就好。

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 15;
int f[N][N], a[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline int jd(int x){ return x < 0 ? -x : x; }
int dfs(int pos, int pre, int lm, int zero)
{
if (pos < 0)
return 1;
if (pre > 0 && !lm && !zero && f[pos][pre] > -1)
return f[pos][pre];
int i, k = lm ? a[pos] : 9, su = 0;
for (i = 0; i <= k; i++)
if (jd(i - pre) > 1)
su += dfs(pos - 1, zero && !i ? -2 : i, lm && i == a[pos], zero && !i);
if (pre > 0 && !lm && !zero)
return f[pos][pre] = su;
return su;
}
int calc(int x)
{
int l = 0;
while (x > 0)
{
a[l++] = x % 10;
x /= 10;
}
return dfs(l - 1, -2, 1, 1);
}
int main()
{
int x, y;
x = re();
y = re();
memset(f, -1, sizeof(f));
printf("%d", calc(y) - calc(x - 1));
return 0;
}

BZOJ1026或洛谷2657 [SCOI2009]windy数的更多相关文章

  1. 洛谷 P2657 [SCOI2009]windy数 解题报告

    P2657 [SCOI2009]windy数 题目描述 \(\tt{windy}\)定义了一种\(\tt{windy}\)数.不含前导零且相邻两个数字之差至少为\(2\)的正整数被称为\(\tt{wi ...

  2. 洛谷——P2657 [SCOI2009]windy数

    P2657 [SCOI2009]windy数 题目大意: windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和 ...

  3. C++ 洛谷 P2657 [SCOI2009]windy数 题解

    P2657 [SCOI2009]windy数 同步数位DP 这题还是很简单的啦(差点没做出来 个位打表大佬请离开(包括记搜),我这里讲的是DP!!! 首先Cal(b+1)-Cal(a),大家都懂吧(算 ...

  4. 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]

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

  5. [洛谷P2657][SCOI2009]windy数

    题目大意:不含前导零且相邻两个数字之差至少为$2$的正整数被称为$windy$数.问$[A, B]$内有多少个$windy$数? 题解:$f_{i, j}$表示数有$i$位,最高位为$j$(可能为$0 ...

  6. 洛谷 P2657 [SCOI2009]windy数

    题意简述 求l~r之间不含前导零且相邻两个数字之差至少为2的正整数的个数 题解思路 数位DP 代码 #include <cstdio> #include <cstring> # ...

  7. 洛谷P2657 [SCOI2009]windy数 题解 数位DP

    题目链接:https://www.luogu.com.cn/problem/P2657 题目大意:找区间 \([A,B]\) 范围内 不含前导零 且 相邻两个数字之差至少为2 的正整数的个数. 题目分 ...

  8. BZOJ1026 SCOI2009 windy数 【数位DP】

    BZOJ1026 SCOI2009 windy数 Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B ...

  9. BZOJ1026: [SCOI2009]windy数[数位DP]

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 6346  Solved: 2831[Submit][Sta ...

随机推荐

  1. Delphi XE4 For IOS之部署问题

    在XE4中编写完程序后,怎么把相应的文件部署到ios虚拟机和真实机子中呢?下面就来说说. 首先选择你要部署的项目,选择Project->Deployment菜单 Deployment菜单打开如下 ...

  2. Node.js express获取参数有三种方法

    express获取参数有三种方法:官网介绍如下 Checks route params (req.params), ex: /user/:id Checks query string params ( ...

  3. https://api.highcharts.com/gantt/

    <a href="https://api.highcharts.com/gantt/">https://api.highcharts.com/gantt/</a& ...

  4. 文件管理 - Ring3创建目录

    //多字符集 #include "stdafx.h" #include <Windows.h> #include <iostream> using name ...

  5. c# word操作篇,解决字符串长度超过255就不能替换的问题

    本文使用的是Microsoft.Office.Interop.Word组件,必须在系统安装了office相关组件的条件下进行,在com里面找到Microsoft  Word 16.0 Object L ...

  6. autofac中文文档

    https://autofaccn.readthedocs.io/zh/latest/index.html

  7. [HNOI2012]射箭(计算几何)

    设抛物线方程\(y = ax^2 + bx\), 那么对于一个靶子\((x_i,y_{down},y_{up})\)我们需要满足的条件就是 \(\frac{y_{down}}{x_i} \leq ax ...

  8. Oracle 循环查询

    select * from sys_department start with departmentid = '0303e461-2454-4d5a-bfea-2cd5a4c064c6' connec ...

  9. 学习笔记 requests + BeautifulSoup

    第一步:requests get请求 # -*- coding:utf-8 -*- # 日期:2018/5/15 17:46 # Author:小鼠标 import requests url = &q ...

  10. kettle数据库连接使用变量

    新增db连接(密码也可以设置参数) 转换中,右键空白处,选择转换设置