-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2318.cpp
More file actions
42 lines (40 loc) · 752 Bytes
/
Copy path2318.cpp
File metadata and controls
42 lines (40 loc) · 752 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
33
34
35
36
37
38
39
40
41
42
#include "common.h"
class Solution {
public:
int distinctSequences(int n) {
return func(n, 7, 7);
}
long long func(int n, int l, int ll) {
if (0 == n) {
return 1;
}
if (dp[n][l][ll]) {
return dp[n][l][ll];
}
long long sum = 0;
for (auto i = 1; i <= 6; ++i) {
if (i == l || i == ll || gcd(i, l) != 1) {
continue;
}
sum += func(n - 1, i, l) % 1000000007;
}
dp[n][l][ll] = sum;
return sum % 1000000007;
}
int gcd(int a, int b) {
if (b > a) {
swap(a, b);
}
while (b) {
int t = b;
b = a % b;
a = t;
}
return a;
}
long long dp[10001][8][8] = {};
};
int main() {
Solution s;
cout << s.distinctSequences(4) << endl;
}