1026: [Scoi2009]windy number time limit:1 Sec Memory limit:162 MB
submit:6346 solved:2831
[Submit] [Status] [Discuss] 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 want to know,
What is 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.
D[i][j] Indicates the number of windy for the first I bit, and the second digit of JInitialize D[1][j]=1and then move directly .Sol does not count the skyline first, then statistics skyline, if (ABS (A[i+1]-a[i]) <2) break;
Note: This also does not count N is not the windy number
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespacestd;Const intn= -, inf=1e9+5;intl,r,d[n][ One];voiddp () { for(intj=0; j<=9; j + +) d[1][j]=1; for(intI=2; i<=Ten; i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) if(ABS (J-K) >=2) d[i][j]+=d[i-1][k];}intSolintN) { inta[n],len=0, ans=0; while(n) a[++len]=n%Ten, n/=Ten; A[len+1]=0; for(inti=len-1; i>=1; i--) for(intj=1; j<=9; j + +) ans+=D[i][j]; for(intj=1; j<a[len];j++) ans+=D[len][j]; //Skyline for(inti=len-1; i>=1; i--){ for(intj=0; j<a[i];j++) if(ABS (a[i+1]-J) >=2) ans+=D[i][j]; if(ABS (a[i+1]-a[i]) <2) Break; } returnans;}intMain () {DP (); scanf ("%d%d",&l,&R); printf ("%d", Sol (r+1)-Sol (L));}
BZOJ1026: [Scoi2009]windy number [digital DP]