Start learning Digital DP ... A problem that saw the code thought yesterday played nearly two hours today. Finally, I saw someone else's code to find a bug ... (lost)
The legend of the Academy is to be canceled? ... It's not a shame to go out with this dish.
#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h > #include <queue>using namespace std;int n,m;///digital DP with 62 and 4 unlucky///DP array used to save the first I-bit with J-start of the auspicious number int dp[11][11];void init () {memset (Dp,0,sizeof (DP)); for (int. i=0;i<=9;i++) dp[1][i]=1;dp[1][4]=0;for (int i=2;i<=7;i++) {for (int j=0;j< =9;j++) {for (int k=0;k<=9;k++) {if (j!=4&&! ( j==6&&k==2)) Dp[i][j]+=dp[i-1][k]; }}}}int cal (int x) {if (x==0) return 1;int a[11];int z=0;while (x>0) {z++; a[z]=x%10; x/=10;} int ans=0; a[z+1]=0;for (int i=z;i>=1;i--) {for (int j=0;j<a[i];j++) {if (j!=4&&! ( a[i+1]==6&&j==2)) Ans+=dp[i][j]; } if ((a[i+1]==6&&a[i]==2) | | | a[i]==4) break;} return ans;} int main () {init (); while (~SCANF ("%d%d", &n,&m)) {if (n==0&&m==0) break; printf ("%d\n", Cal (m+1)-cal (n));}}
HDU 2089 Digital DP entry