HDOJ 2089 数位DP

链接:

http://acm.hdu.edu.cn/showproblem.php?pid=2089

题意:

给你一个区间,问你这个区间有多少个数字不包含4 和 62

代码:

31 int a[20];
32 int dp[20][2];
33 
34 int dfs(int pos, int pre, int sta, bool limit) {
35     if (pos == -1) return 1;
36     if (!limit && dp[pos][sta] != -1) return dp[pos][sta];
37     int up = limit ? a[pos] : 9;
38     int res = 0;
39     rep(i, 0, up + 1) {
40         if (i == 2 && pre == 6) continue;
41         if (i == 4) continue;
42         res += dfs(pos - 1, i, i == 6, limit && i == a[pos]);
43     }
44     if (!limit) dp[pos][sta] = res;
45     return res;
46 }
47 
48 int solve(int x) {
49     int pos = 0;
50     while (x) {
51         a[pos++] = x % 10;
52         x /= 10;
53     }
54     return dfs(pos - 1, -1, 0, true);
55 }
56 
57 int main() {
58     ios::sync_with_stdio(false), cin.tie(0);
59     int l, r;
60     while (cin >> l >> r, l + r) {
61         memset(dp, -1, sizeof(dp));
62         cout << solve(r) - solve(l - 1) << endl;
63     }
64     return 0;
65 }

 

转载于:https://www.cnblogs.com/baocong/p/6805097.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值