-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_13.cpp
More file actions
67 lines (50 loc) · 1.52 KB
/
Copy pathLab_13.cpp
File metadata and controls
67 lines (50 loc) · 1.52 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1000000007;
long long power(long long base, long long exp) {
long long res = 1;
base %= MOD;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % MOD;
base = (base * base) % MOD;
exp /= 2;
}
return res;
}
void solve() {
int n, m;
if (!(cin >> n >> m)) return;
if (m == 0) {
cout << 0 << endl;
return;
}
vector<long long> T(m + 1, 0);
T[0] = 1;
for (int i = 1; i <= m; ++i) {
if (i >= 1) T[i] = (T[i] + T[i - 1]) % MOD;
if (i >= 2) T[i] = (T[i] + T[i - 2]) % MOD;
if (i >= 3) T[i] = (T[i] + T[i - 3]) % MOD;
if (i >= 4) T[i] = (T[i] + T[i - 4]) % MOD;
}
vector<long long> W(m + 1, 0);
for (int i = 1; i <= m; ++i) {
long long total_arrangements = power(T[i], n);
long long arrangements_with_crack = 0;
for (int k = 1; k < i; ++k) {
long long remaining_ways = power(T[i - k], n);
long long term = (W[k] * remaining_ways) % MOD;
arrangements_with_crack = (arrangements_with_crack + term) % MOD;
}
W[i] = (total_arrangements - arrangements_with_crack + MOD) % MOD;
}
cout << W[m] << endl;
}
int main() {
ios_base::sync_with_st
dio(false);
cin.tie(NULL);
solve();
return 0;
}