-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3699.cpp
More file actions
32 lines (32 loc) · 845 Bytes
/
Copy path3699.cpp
File metadata and controls
32 lines (32 loc) · 845 Bytes
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
28
29
30
31
32
class Solution {
public:
int zigZagArrays(int n, int l, int r) {
int mod = 1e9 + 7;
r -= l;
vector<int> dp(r + 1, 1);
for (int i = 1; i < n; ++i) {
int preSum = 0;
int temp = 0;
if (i & 1) {
for (int k = 0; k <= r; ++k) {
temp = (preSum + dp[k]) % mod;
dp[k] = preSum;
preSum = temp;
}
}
else {
for (int k = r; k >= 0; --k) {
temp = (preSum + dp[k]) % mod;
dp[k] = preSum;
preSum = temp;
}
}
}
int res = 0;
for (auto& num : dp) {
res += num;
res %= mod;
}
return (res * 2) % mod;
}
};