力扣9.28-代码

时间:2024-10-02 13:44:58
class Solution {
public:
    const static int N = 1e5 + 5, mod = (int)1e9 + 7;
    unsigned long long dp[N];
    unsigned long long countGoodStrings(int low, int high, int zero, int one) {
        dp[0] = 1;
        unsigned long long res = 0;
        for(int i = 1; i <= high; i ++ ) {
            if(i >= zero) dp[i] += dp[i - zero];
            if(i >= one) dp[i] += dp[i - one];
            if(i >= low) res += dp[i];
            dp[i] %= mod;
            res %= mod;
        }
        return res;
    }
};