2023-05-13 23:56:24 +02:00
|
|
|
#include <cassert>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Solution {
|
2024-01-03 12:06:42 +01:00
|
|
|
constexpr static int MOD = 1000000007;
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
static void add_with_mod(std::vector<int> &good, std::size_t i, int value) {
|
|
|
|
good[i] = (good[i] + value) % MOD;
|
|
|
|
}
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
|
|
|
int countGoodStrings(int low, int high, int zero, int one) {
|
|
|
|
assert(low <= high);
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
std::vector<int> good(high + 1, 0);
|
|
|
|
good[0] = 1;
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
for (int length = 1; length <= high; ++length) {
|
|
|
|
if (length >= zero) {
|
|
|
|
add_with_mod(good, length, good[length - zero]);
|
|
|
|
}
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
if (length >= one) {
|
|
|
|
add_with_mod(good, length, good[length - one]);
|
|
|
|
}
|
|
|
|
}
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
int total = 0;
|
|
|
|
for (int i = low; i <= high; ++i) {
|
|
|
|
total = (total + good[i]) % MOD;
|
|
|
|
}
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
return total;
|
|
|
|
}
|
2023-05-13 23:56:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
2024-01-03 12:06:42 +01:00
|
|
|
Solution s;
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
assert(s.countGoodStrings(3, 3, 1, 1) == 8);
|
|
|
|
assert(s.countGoodStrings(2, 3, 1, 2) == 5);
|
2023-05-13 23:56:24 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
return 0;
|
2023-05-13 23:56:24 +02:00
|
|
|
}
|