1026: [Scoi2009]windy number
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
http://www.lydsy.com/JudgeOnline/problem.php?id=1026
Descriptionwindy 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"
25 50
Sample Output
"Output Example One"
9
"Output Example II"
20
HINT
"Data size and conventions"
100% data, meet 1 <= A <= B <= 2000000000.
Test instructions
Exercises
than the weaker digital DP, just run naked.
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)#defineMAXN 2000001#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;} while(x>0) ch[++num]=x%Ten, x/=Ten; while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************intl,r,dp[ the][ the],bit[ the]; voidPre () { for(intI=0; i<=9; i++) dp[1][i]=1; for(intI=2; i<=Ten; i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) if(ABS (J-K) >=2) Dp[i][j]+=dp[i-1][k]; }intWorkintN) { intlen=0, ans=0; memset (bit,0,sizeof(bit)); while(n) {bit[++len]=n%Ten; N/=Ten; } for(intI=1; i<=len-1; i++) for(intj=1; j<=9; j + +) ans+=Dp[i][j]; for(intI=1; i<bit[len];i++) ans+=Dp[len][i]; for(inti=len-1;i>0; i--) { for(intj=0; j<bit[i];j++) if(ABS (j-bit[i+1]) >=2) ans+=Dp[i][j]; if(ABS (bit[i]-bit[i+1]) <2) Break; } returnans; } intMain () {pre (); scanf ("%d%d",&l,&R); printf ("%d", Work (r+1)-Work (L)); return 0; }
Bzoj 1026 [Scoi2009]windy-Digital DP