---
# System prepended metadata

title: 2466. Count Ways To Build Good Strings
tags: [Leetcode, Dynamic Programming, Medium]

---

# 2466. Count Ways To Build Good Strings
###### tags: `Leetcode` `Medium` `Dynamic Programming`
Link: https://leetcode.com/problems/count-ways-to-build-good-strings/description/
## 思路
和[0518. Coin Change 2](https://hackmd.io/azimrNJRRUK0CBaC2d0Ivg)差不多
```dp[i] = dp[i-zero]+dp[i-one]```
## Code
```java=
class Solution {
    public int countGoodStrings(int low, int high, int zero, int one) {
        long[] dp = new long[high+1];
        dp[0] = 1;
        long ans = 0;
        int mod = 1000000007;
        for(int i=1; i<=high; i++){
            if(i-zero>=0) dp[i] = (dp[i]+dp[i-zero])%mod;
            if(i-one>=0) dp[i] = (dp[i]+dp[i-one])%mod;
            if(i>=low && i<=high) ans = (ans+dp[i])%mod;
        }
        return (int)ans;
    }
}
```
