CodeForces 204A Little Elephant and Interval 数位DP
2015-02-09 13:18
369 查看
#include <cstdio> #include <cstring> using namespace std; typedef __int64 LL; int a[33]; LL dp[33][10]; LL dfs(int x, int s, int e, int flag, int first) { if(x == -1) return s == e; if(!flag && dp[x][s]!= -1) return dp[x][s]; int end = 9; if(flag) end = a[x]; LL sum = 0; for(int i = 0; i <= end; i++) { int st = s, ed = e; if(!first && i) st = i; if(x == 0) ed = i; sum += dfs(x-1, st, ed, flag && i == end, first||i); } if(!flag) dp[x][s] = sum; return sum; } LL cal(LL x) { if(x == 0) return 1; int l = 0; while(x) { a[l++] = x%10; x /= 10; } return dfs(l-1, 0, -1, 1, 0); } int main() { int T; memset(dp, -1, sizeof(dp)); LL x, y; while(scanf("%I64d %I64d", &x, &y) != EOF) { if(!x && !y) break; printf("%I64d\n", cal(y)-cal(x-1)); } return 0; }
相关文章推荐
- codeforces 55D. Beautiful numbers(数位dp)
- Codeforces 204A Little Elephant and Interval(数位DP)
- Codeforces-55D Beautiful numbers (数位DP)
- CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
- codeforces_628D. Magic Numbers(数位dp)
- Codeforces 55D - Beautiful numbers(数位dp)好
- CodeForces 55D 数位DP 能被它自身数位上的所有数整除
- Codeforces 840E In a Trap 分块+数位dp
- 【数位DP】 Codeforces 55D Beautiful numbers
- Codeforces 55D Beautiful numbers 数位dp
- CodeForces 258 B.Little Elephant and Elections(数位DP+dfs)
- codeforces 55D Beautiful numbers[数位dp]
- CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
- CodeForces 55D Beautiful numbers (数位DP+状态简化,5级)
- Codeforces 55D Beautiful numbers(数位dp)
- codeforces 204A Little Elephant and Interval (数位dp)
- Codeforces 628D Magic Numbers 【数位dp】
- CodeForces 55D Beautiful numbers (数位DP)
- Magic Numbers CodeForces - 628D (数位dp)