# "bzoj1026" "SCOI2009" "Windy number" "Digital DP"

Source: Internet
Author: User

Description

Windy defines a windy number. A positive integer that does not contain a leading 0 and the difference of at least 2 of the adjacent two digits is called the windy number. Windy would like to know the total number of windy between A and B, including A and b?

Input

Contains two integers, A B.

Output

An integer.

Sample Input"Input Sample One"
1 10
"Input Sample Two"
theSample Output"Output Example One"
9
"Output Example II"
-HINT

"Data size and conventions"

100% data, meet 1 <= A <= B <= 2000000000.

The puzzle: It's obviously a digital DP. We set F[I][J] to indicate the number of I digits, the highest bit is the number of J's qualifying numbers. So

F[i][j]=sigma (F[i-1][k]) (ABS (J-K) >=2);

Then the direct set of the digital DP is good.

`#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib    >using namespace Std;int x,f,l,r,up;int work (int x) {if (x==0) return 0;    int t (0), ans (0), W,pre;    while (x>0) {t++;w[t]=x%10;x/=10;}    for (int. i=1;i<t;i++) for (int j=1;j<=9;j++) ANS+=F[I][J];    for (int j=1;j<w[t];j++) ANS+=F[T][J];    PRE=W[T];        for (int i=t-1;i>0;i--) {if (I==1&&abs (w[i]-pre) >=2) ans++;        for (int j=0;j<=min (pre-2,w[i]-1); j + +) Ans+=f[i][j];         for (int j=pre+2;j<=w[i]-1;j++) ANS+=F[I][J];        if (ABS (W[I]-PRE) <2) break;      Pre=w[i]; } return ans;    int main () {scanf ("%d%d", &l,&r);     for (int i=0;i<=9;i++) f[i]=1;    X=r;    while (x>0) {up++;x/=10;} for (int i=2;i<=up;i++) for (int. j=0;j<=9;j++) {for (int k=j+2;k<=9;k++) f[i][j]+=f[i-1][k]          ; for (int k=j-2;k>=0;k--) f[i][j]+=f[i-1][K]; } printf ("%d", work (R)-work (L-1)); }`

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"bzoj1026" "SCOI2009" "Windy number" "Digital DP"

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.