标签:== ram line cti article width play stc 数位dp
int f[20][10], bits[20]; int dfs(int pos, int pre, bool lmt, bool first) { if (pos == -1) return 1; if (!lmt && !first && ~f[pos][pre]) return f[pos][pre]; int u = lmt ?bits[pos] : 9, ret = 0; for (int i = 0; i <= u; i++) { if (first || (!first && abs(pre - i) >= 2)) ret += dfs(pos - 1, i, lmt && i == u, first && !i); } return lmt || first ? ret : f[pos][pre] = ret; } int calc(int n) { CLR(f, -1); int len = 0; while (n) { bits[len++] = n % 10; n /= 10; } return dfs(len - 1, 0, true, true); } int main() { //freopen("0.txt", "r", stdin); int a, b; while (~RII(a, b)) { cout << calc(b) - calc(a - 1) << endl; } return 0; }
标签:== ram line cti article width play stc 数位dp
原文地址:http://www.cnblogs.com/yfceshi/p/6848535.html