• AcWing 1082. 数字游戏


    题目传送门

    无脑模板,套进去\(AC\)

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 35;
    
    int l, r;
    int a[N], al;
    int f[N][N];
    /**
     *
     * @param pos 当前的数位
     * @param st  前一位填写的是什么
     * @param op  是不是贴上界
     * @return    在当前情况下,后续符合条件的有多少个
     */
    int dp(int pos, int st, int op) {
        if (!pos) return 1; //如果走完所有情况,还活着,说明前面的都符合条件,就是一个合理解++
        if (!op && ~f[pos][st]) return f[pos][st];
        int res = 0, up = op ? a[pos] : 9;
        for (int i = st; i <= up; i++)//注意起始点,i >= pre
            res += dp(pos - 1, i, op && i == a[pos]);
        return op ? res : f[pos][st] = res;
    }
    
    int calc(int x) {
        memset(f, -1, sizeof f);
        al = 0;
        while (x) a[++al] = x % 10, x /= 10;
        return dp(al, 0, 1);
    }
    
    int main() {
        while (cin >> l >> r)
            cout << calc(r) - calc(l - 1) << endl;
        return 0;
    }
    
  • 相关阅读:
    [virsh] error: unknown OS type hvm解决办法
    TCP长连接与短连接的区别
    MySQL数据优化总结-查询备忘录
    Tomcat 调优测试
    MySQL的分表与分区
    iptables防火墙入门
    regex正则
    xtrabackup
    锁&lock与latch
    文档测试
  • 原文地址:https://www.cnblogs.com/littlehb/p/15793107.html
Copyright © 2020-2023  润新知