My Solution
\nclass Solution {\n public:\n  int countSubMultisets(const vector<int> &nums, const int l, const int r) {\n    constexpr int range = 2;\n    constexpr int mod 
```\nclass Solution {\n public:\n  int countSubMultisets(const vector<int> &nums, const int l, const int r) {\n    constexpr int range = 2;\n    constexpr int mod = 1000000007;\n    unordered_map<int, int> num_to_count;\n    for (const int num : nums) {\n      ++num_to_count[num];\n    }\n    \n    auto itr_zero = num_to_count.find(0);\n    const int zero_count = itr_zero == num_to_count.end() ? 0 : itr_zero->second;\n    if (itr_zero != num_to_count.end()) {\n      num_to_count.erase(itr_zero);\n    }\n\n    const int n = static_cast<int>(num_to_count.size());\n    /**\n     * dp[i][j] stands for the count of sub-multisets within the first `i` numbers\n     * in the unordered_map<int, int> `num_to_count`\n     * where the sum of elements in each subset is equal to `j`\n     * please note for each number `num` of `num_to_count`, there exist `num_to_count[num]` `num`s\n     *\n     * initial:\n     * dp[0][0] = 1 + `zero_count`\n     *\n     * induction:\n     * for a number `num` in `num_to_count`, let `count` = `num_to_count[num]`\n     * dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1 * num] + dp[i - 1][j - 2 * num] + ... + dp[i - 1][j - count * num]\n     * dp[i][j - num] = dp[i - 1][j - 1 * num] + dp[i - 1][j - 2 * num] + ... + dp[i - 1][j - (count + 1) * num]\n     * the following induction can be got\n     * dp[i][j] = dp[i - 1][j] + dp[i][j - num] - dp[i - 1][j - (count + 1) * num]\n     *\n     * target:\n     * accumulate(dp[num_to_count.size()] + l, dp[num_to_count.size()] + r + 1, 0)\n     */\n    int dp[range][r + 1];\n    memset(dp, 0, sizeof(dp));\n    int previous = 0;\n    int current = 1;\n    dp[previous][0] = 1 + zero_count;\n    for (const auto [num, count] : num_to_count) {\n      for (int sum = 0; sum < r + 1; ++sum) {\n        dp[current][sum] = dp[previous][sum];\n        if (sum >= num) {\n          dp[current][sum] = (dp[current][sum] + dp[current][sum - num]) % mod;\n        }\n        if (sum >= static_cast<long long>(count + 1) * num) {\n          dp[current][sum] = (mod + dp[current][sum] - dp[previous][sum - (count + 1) * num]) % mod;\n        }\n      }\n      \n      previous ^= 1;\n      current ^= 1;\n      memset(dp[current], 0, sizeof(dp[current]));\n    }\n    \n    int ret = 0;\n    for (int i = l; i < r + 1; ++i) {\n      ret = (ret + dp[previous][i]) % mod;\n    }\n    return ret;\n  }\n};\n```
[]