[SCOI2009]windy数 BZOJ1026 数位dp
题目描述
windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道,
在A和B之间,包括A和B,总共有多少个windy数?
输入输出格式
输入格式:
包含两个整数,A B。
输出格式:
一个整数
输入输出样例
说明
100%的数据,满足 1 <= A <= B <= 2000000000 。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 100005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 100000007;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll dp[20][20], ans;
int a[maxn];
int len;
ll l, r; ll dfs(int pos, int pre, int lead, int limit) {
if (pos > len)return 1;
if (!limit&&dp[pos][pre] != -1)return dp[pos][pre];
ll res = 0;
int up = limit ? a[len - pos + 1] : 9;
for (int i = 0; i <= up; i++) {
if (abs(i - pre) < 2)continue;
if (lead&&i == 0)res += dfs(pos + 1, -2, 1, limit&&i == up);
else res += dfs(pos + 1, i, 0, limit&i == up);
}
if (!limit && !lead)dp[pos][pre] = res;
return res;
} ll sol(ll x) {
len = 0;
while (x)a[++len] = x % 10, x /= 10;
mclr(dp, -1);
return dfs(1, -2, 1, 1);
} int main()
{
// ios::sync_with_stdio(0);
rdllt(l); rdllt(r);
cout << (ll)sol(r) - (ll)sol(l - 1) << endl;
return 0;
}
[SCOI2009]windy数 BZOJ1026 数位dp的更多相关文章
- BZOJ_1026_[SCOI2009]windy数_数位DP
BZOJ_1026_[SCOI2009]windy数_数位DP 题意:windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之 ...
- [bzoj1026][SCOI2009]windy数_数位dp
windy数 bzoj-1026 题目大意:求一段区间中的windy数个数. 注释:如果一个数任意相邻两位的差的绝对值都不小于2,这个数就是windy数,没有前导0.$区间边界<=2\cdot ...
- bzoj1026: [SCOI2009]windy数(数位dp)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 8203 Solved: 3687[Submit][Sta ...
- 2018.06.30 BZOJ1026: [SCOI2009]windy数(数位dp)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MB Description windy定义了一种windy数.不含前导零且相邻两 ...
- BZOJ1026 SCOI2009 windy数 【数位DP】
BZOJ1026 SCOI2009 windy数 Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B ...
- bzoj 1026 [SCOI2009]windy数(数位DP)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4550 Solved: 2039[Submit][Sta ...
- 1026: [SCOI2009]windy数(数位dp)
1026: [SCOI2009]windy数 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 9016 Solved: 4085[Submit][Sta ...
- 1026. [SCOI2009]windy数【数位DP】
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个windy数? I ...
- 【BZOJ】1026: [SCOI2009]windy数(数位dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1026 我果然很弱啊... 考虑数位dp.枚举每一位,然后限制下一位即可. 一定要注意啊!在dfs的时 ...
随机推荐
- OSCache-JSP页面缓存(1)
一.OSCache提供的缓存标签 这是OSCache提供的标签库中最重要的一个标签,包括在标签中的内容将应用缓存机制进行处理,处理的方式将取决于编程者对cache标签属性的设置. 第一次请求到达时,标 ...
- ReactNative项目创建及结构分析
- php 实现百度文库搭建
第一步:安装jodconverter,安装之后可以实现doc文档转成pdf. 文件下载地址为http://www.artofsolving.com/opensource/jodconverter 下载 ...
- Python编写两个数的加减法游戏
目标: 1.实现两个数的加减法 2.回答者3次输错计算结果后,输出正确结果,并询问回答者是否继续 1.使用常规函数实现两个数的加减法游戏 代码如下: #!/usr/bin/env python # - ...
- struts2 与 spring 整合
1. 首先把所有jar包导入工程 2.在struts2的核心配置文件(在src文件目录下)中添加如下配置: <!-- 将Struts的对象交给Spring管理 所以需要导入Spring和Stru ...
- Docker学习之路(三)Docker网络详解
1. Docker的4种网络模式 我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下4种网络模式: host模式,使用--net=host ...
- 新浪SAE高级开发者认证通过
如题,新浪SAE高级开发者认证通过,申请的方式为提交开源项目地址,用的是如下的项目 http://jqext.sinaapp.com/ 之前该项目是部署在 mopaas 上的,在拿到高级开发者资格后迁 ...
- 30.MIN() 函数
MIN() 函数 MIN 函数返回一列中的最小值.NULL 值不包括在计算中. SQL MIN() 语法 SELECT MIN(column_name) FROM table_name 注释:MIN ...
- dynamic和匿名类和var的混合使用 没提示照样点
using System;using System.Collections;using System.Collections.Generic;using System.Linq;using Syste ...
- [GO]不同作用域的同名变量
package main import "fmt" var a byte //这是一个全局变量 func main() { var a int //这是一个局部变量 //1.作用域 ...