【BZOJ1026】【SCOI2009】windy数

传送门~:http://www.lydsy.com/JudgeOnline/problem.php?id=1026

数位dp傻题QaQ

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <iostream>
 5 using namespace std;
 6 int f[15][15], A, B, da[15];
 7 void get_ready(){
 8     for (int i = 0; i <= 9; i++) f[1][i] = 1; 
 9     for (int i = 2; i <= 10; i++){
10         for (int j = 0; j <= 9; j++) {
11             for (int k = 0; k <= 9; k++) {
12                 if (abs(j-k) >= 2)    f[i][j] += f[i-1][k];
13             }
14         }
15     }
16 }
17 
18 int calc(int a){
19     if (a == 0) return 0;
20     int ret = 0, len = 0;
21     do{
22         da[++len] = a % 10;
23         a /= 10;
24     }while(a);
25     for (int i = 1; i < len; i++)
26         for (int j = 1; j <= 9; j++)
27             ret += f[i][j];
28     for (int i = 1; i < da[len]; i++) ret += f[len][i];
29     for (int i = len-1; i > 0; i--) {
30         for (int j = 0; j < da[i]; j++)
31             if (abs(j-da[i+1]) >= 2) ret += f[i][j];
32         if (abs(da[i]-da[i+1]) < 2) break;
33     }
34     return ret;
35 }
36 
37 int main(){
38     freopen("bzoj1026.in", "r", stdin);
39     freopen("bzoj1026.out", "w", stdout);
40     get_ready();
41     scanf("%d%d", &A, &B);
42     printf("%d\n", calc(B+1) - calc(A));
43     return 0;
44 }
_(:з」∠)_

 

你可能感兴趣的:(【BZOJ1026】【SCOI2009】windy数)