Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1026
Quite simple digital DP, pre-F[I][J] represents the number of I digits, the number of windy starting with J;
But do not understand why the last one to take out a special sentence ret++ wrong, and write in the loop, special i==1 on the right ...
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;inta,b,f[ the][ the],num[ the];intAbbintx) {return(x>0)? x:-x;}intGetnum (intx) { intCnt=0; while(x) num[++cnt]=x%Ten, x/=Ten; returnCNT;}voidinit () {intmx=Getnum (b); for(intI=0; i<=9; i++) f[1][i]=1; for(intI=2; i<=mx;i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) if(ABB (J-K) >=2) f[i][j]+=f[i-1][k];}intCalcintx) { intMx=getnum (x), ret=0; for(intI=1; i<mx;i++) for(intj=1; j<=9; j + +) ret+=F[i][j]; for(intj=1; j<num[mx];j++) ret+=F[mx][j]; for(inti=mx-1, pre;i;i--) {Pre=num[i+1]; if(i!=1) { for(intj=0; j<num[i];j++) if(ABB (PRE-J) >=2) ret+=F[i][j]; } if(i==1)//AC { for(intj=0; j<=num[i];j++) if(ABB (PRE-J) >=2) ret+=F[i][j]; } if(ABB (Num[i]-pre) <2) Break;//! }//if (mx==1| | ABB (Num[1]-num[2]) >=2) ret++;//WA//if (ABB (num[1]-num[2)) >=2) ret++;//WA returnret;}intMain () {scanf ("%d%d",&a,&b); Init (); printf ("%d\n", Calc (b)-calc (A-1)); return 0;}
Bzoj 1026 [SCOI2009] Windy number--digit DP