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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B;
int k[20],pos;//存数字各位
ll dp[20][10];//第i位为j的数字个数(不能大小限制)
/*
pos : 当前考虑的第pos位,例如十进制数12345,5为第0位
pre : 当前位的前一位的数字
lead : 是否有前导0,比如之前枚举的两位 00xxx,在枚举3位时是有前导0的。
limit : 是否有大小限制,比如枚举了12xxx,在枚举3位时最大枚举到3
*/
ll dfs(int pos,int pre,bool lead,bool limit){
if(pos == -1) return 1;
if(!limit && !lead && dp[pos][pre])return dp[pos][pre];
int up = limit ? k[pos] : 9;//确定枚举上界
ll res = 0;
for(int i=0;i<=up;i++){
if(lead){
if(i == 0){
res += dfs(pos-1,0,true,false);
}
else{
res += dfs(pos-1,i,false,limit && i == k[pos]);
}
}else{
if(abs(i-pre) < 2)continue;
res += dfs(pos-1,i,false,limit && i == k[pos]);
}
}
if(!limit && !lead)dp[pos][pre] = res;
return res;
}
ll solve(ll x){
int pos = 0;
while(x){
k[pos++] = x % 10;
x /= 10;
}
return dfs(pos-1,0,true,true);
}
int main(){
scanf("%lld%lld",&A,&B);
printf("%lld\n",solve(B) - solve(A-1));
return 0;
}

最新文章

  1. PHP WAMP 文件上传 及 简单的上传预览
  2. ASP.NET MVC3 301永久重定向实现程序
  3. C#的语句
  4. Docker容器的数据管理
  5. ubuntu上搭建工作环境
  6. leetcode之Find All Numbers Disappeared in an Array
  7. 信息论随笔3: 交叉熵与TF-IDF模型
  8. 使用Jenkins部署asp.net core
  9. Kafka: Exactly-once Semantics
  10. 使用synchronized同步,经典银行账户问题
  11. php中的一些不常见的问题foreach/in_array[开发篇]
  12. NodeJS简单爬虫
  13. 004.HAProxy的管理与维护
  14. node-rsa 非对称加密和解密
  15. Android Studio 新建drawable-hdpi、drawable-mdpi等
  16. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze 最短路+分层图
  17. GIT(4)----免输入账号和密码方法
  18. eclipse javaee 插件安装
  19. jQuery语法小结(超实用)
  20. [爬虫] 学Scrapy,顺便把它的官方教程给爬下来

热门文章

  1. windows端口占用
  2. Serverless 如何应对 K8s 在离线场景下的资源供给诉求
  3. 了解一下RPC,为何诞生RPC,和HTTP有什么不同?
  4. L(kali)A(apache)M(mysql)P(php)环境+wordpress站点搭建
  5. oracle move表空间(分区表,索引)
  6. cfsetispeed、cfsetospeed和cfsetspeed探究
  7. VGA调试心得
  8. 最佳的思维导图生成工具——markmap 使用教程
  9. JavaScript中的Object类型!
  10. Azure Terraform(七)利用Azure DevOps 实现自动化部署基础资源(补充)