-
Notifications
You must be signed in to change notification settings - Fork 3
/
2466.cpp
27 lines (27 loc) · 868 Bytes
/
2466.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int countGoodStrings(int low, int high, int zero, int one) {
long long mod = 1e9 + 7;
vector<long long> endWithZero(high + 1, 0);
vector<long long> endWithOne(high + 1, 0);
endWithZero[zero] = 1;
endWithOne[one] = 1;
long long res = 0;
for (int i = 1; i <= high; ++i) {
if (i - zero > 0) {
endWithZero[i] = endWithZero[i - zero] + endWithOne[i - zero];
}
if (i - one > 0) {
endWithOne[i] = endWithZero[i - one] + endWithOne[i - one];
}
endWithZero[i] %= mod;
endWithOne[i] %= mod;
if (i >= low && i <= high) {
res += endWithZero[i];
res += endWithOne[i];
res %= mod;
}
}
return res;
}
};