[BZOJ1026]windy数

Description

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

Input

  包含两个整数,A B。

Output

  一个整数

Sample Input

【输入样例一】
1 10
【输入样例二】
25 50

Sample Output

【输出样例一】
9
【输出样例二】
20

HINT

【数据规模和约定】

100%的数据,满足 1 <= A <= B <= 2000000000 。

Source

数位dp模板题

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #define int long long
 6 using namespace std;
 7 int l,r,a[21],dp[21][1001];
 8 int dfs(int pos,int sta,bool lead,bool limit)
 9 {
10     if(pos==0) return 1;
11     if(!lead&&!limit&&dp[pos][sta]!=-1) return dp[pos][sta];
12     int up=limit?a[pos]:9;
13     int ans=0;
14     for(int i=0;i<=up;i++)
15     {
16         if(abs(i-sta)<2) continue;
17         ans+=dfs(pos-1,(i==0&&lead)?1000:i,(i==0&&lead),(limit&&i==up));
18     }
19     if(!limit&&!lead) dp[pos][sta]=ans;
20     return ans;
21 }
22 int solve(int x)
23 {
24     int cnt=0;
25     while(x!=0)
26     {
27         a[++cnt]=x%10;
28         x/=10;
29     }
30     memset(dp,-1,sizeof(dp));
31     return dfs(cnt,1000,1,1);
32 }
33 #undef int
34 int main()
35 {
36     #define int long long
37     cin>>l>>r;
38     cout<<solve(r)-solve(l-1);
39     return 0;
40 }

 

转载于:https://www.cnblogs.com/Slrslr/p/9712058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值