Title Description
windy defines a number windy. Without leading zeros and adjacent to at least the difference between two numbers is called a positive integer number windy. windy want to know,
Between A and B, including A and B, total number of windy number?
Input Format
It contains two integers, AB.
Output Format
An integer
Sample input and output
Input # 1
1 10
Output # 1
9
Input # 2
25 50
Output # 2
20
Description / Tips
100% data satisfies 1 <= A <= B <= 2000000000.
Solution: dp digital solution, provided dp [i] [J] of length i is the number of bits in the highest number of windy j
Equation dp [i] [j] = sum (dp [i-1] [k]), such a transfer is transferred from the former and by
#include<cstdio> #include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> typedef long long ll; using namespace std; int f[22][22],a[22]; void Cang_Shu_Xia(){ for(int i=0;i<=9;i++) f[1][i]=1; for(int i=2;i<=10;i++) for(int j=0;j<=9;j++) for(int k=0;k<=9;k++) if(abs(j-k)>=2) f[i][j]+=f[i-1][k]; } int len,ans; int Yao_Chen_Lai_Le(int x){ memset(a,0,sizeof(a)); len=0; ans=0; while(x){ a[++len]=x%10; x/=10; } for(int i=1;i<len;i++) for(int j=1;j<=9;j++) ans+=f[i][j]; for(int i=1;i<a[len];i++) ans+=f[len][i]; for(int i=len-1;i>=1;i--){ for(int j=0;j<=a[i]-1;j++) if(abs(j-a[i+1])>=2) ans+=f[i][j]; if(abs(a[i+1]-a[i])<2) break; } return ans; } int main(){ freopen("2657.in","r",stdin); freopen("2657.out","w",stdout); Cang_Shu_Xia(); int n,m; cin>>n>>m; cout<<Yao_Chen_Lai_Le(m+1)- Yao_Chen_Lai_Le(n); return 0; }