const int MAXN = 110; int dp[MAXN][MAXN][10]; char comp[MAXN], ipta[MAXN], iptb[MAXN]; char* bits; int len, lcp; bool check(int a, int b, char cp) { if (cp == '-') return a == b; else if (cp == '/') return a < b; else return a > b; } int dfs(int pos, int idx, int pre, bool lmt, bool fst) { if (pos == len) { return idx == lcp; } if (!lmt && !fst && ~dp[pos][idx][pre]) return dp[pos][idx][pre]; int e = 9, ret = 0; e = lmt ? bits[pos] - '0' : 9; FE(i, 0, e) { if (fst) ret += dfs(pos + 1, idx, i, lmt && i == e, fst && !i); else { if (idx < lcp && check(pre, i, comp[idx])) ret += dfs(pos + 1, idx + 1, i, lmt && i == e, 0); else if (idx > 0 && check(pre, i, comp[idx - 1])) ret += dfs(pos + 1, idx, i, lmt && i == e, 0); } ret %= MOD; } return lmt || fst ? ret : dp[pos][idx][pre] = ret; } int calc(char x[], bool sub) { CLR(dp, -1); len = strlen(x); int t = 0; while (x[t] == '0') t++; if (t >= len) return 0; if (sub) for (int i = len - 1; i >= t; i--) { if (x[i] != '0') { x[i]--; break; } else { x[i] = '9'; } } bits = x; return dfs(t, 0, 0, true, true); } int main() { while (~RS(comp)) { lcp = strlen(comp); scanf("%s%s", ipta, iptb); printf("%08d\n", ((calc(iptb, false) - calc(ipta, true)) % MOD + MOD) % MOD); } return 0; }
原文地址:http://blog.csdn.net/wty__/article/details/38150263