您的位置:首页 > 其它

BZOJ 1026: [SCOI2009]windy数

2017-12-27 21:43 232 查看
二次联通门 : BZOJ 1026: [SCOI2009]windy数

/*
水题开心
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#define rg register

int f[20][20], c[20], cur;
inline int abs (int x) {
return x < 0 ? -x : x;
}
int dfs (int n, int l, bool led, bool lim) {
if (n == 0) return 1;
if (!lim && !led && f
[l] >= 0) return f
[l];
int up = lim ? c
: 9, res = 0;
for (int i = 0; i <= up; ++ i) {
if (!led && abs (i - l) < 2 && n != cur) continue;
if (led && i == 0) res += dfs (n - 1, i, true, lim && i == up);
else res += dfs (n - 1, i, led && i == 0, lim && i == up);
}
return (!lim && !led) ? f
[l] = res : res;
}

int sv (int key) {
for (cur = 0; key; c[++ cur] = key % 10, key /= 10);
return dfs (cur, 0, true, true);
}
int main (int argc, char *argv[]) {
int A, B; scanf ("%d%d", &A, &B);
memset (f, -1, sizeof f);
printf ("%d", sv (B) - sv (A - 1));
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: