G

Untitled

public
Guest Oct 30, 2024 Never 50
Clone
C++ paste1.cpp 88 lines (77 loc) | 1.75 KB
1
#include<bits/stdc++.h>
2
3
using namespace std;
4
typedef long long ll;
5
#define sz(s) (int)(s).size()
6
#define all(s) s.begin(),s.end()
7
8
void Speed() {
9
ios_base::sync_with_stdio(false);
10
cin.tie(NULL);
11
}
12
13
const int M = 1e9 + 7;
14
int add(int a, int b){
15
return (a + b) % M;
16
}
17
int mul(int a, int b){
18
return 1ll * a * b % M;
19
}
20
21
struct matrix{
22
int n;
23
using row = vector<int>;
24
vector<vector<int>> v;
25
matrix() {}
26
matrix(int n, int val = 0) : n(n), v(n, row(n, val)){}
27
28
matrix operator*(const matrix &other) const{
29
matrix ret(n);
30
for(int i = 0; i < n; i++){
31
for(int k = 0; k < n; k++){
32
if(this->v[i][k] == 0) continue;
33
for(int j = 0; j < n; j++){
34
ret.v[i][j] = add(ret.v[i][j], mul(this->v[i][k], other.v[k][j]));
35
}
36
}
37
}
38
return ret;
39
}
40
};
41
42
matrix Identity(int n) {
43
matrix ret(n);
44
for (int i = 0; i < n; i++) ret.v[i][i] = 1;
45
return ret;
46
}
47
48
matrix power(matrix& a, ll k){
49
matrix res = Identity(a.n);
50
while(k){
51
if(k & 1) res = res * a;
52
k >>= 1; a = a * a;
53
}
54
return res;
55
}
56
57
void solve() {
58
int n, k; cin >> n >> k;
59
matrix mat1(103), mat2(103);
60
vector<int> freq(102);
61
for(int i = 0; i < n; i++){
62
int a; cin >> a; freq[a]++;
63
}
64
65
mat1.v[0][0] = 1;
66
for(int i = 1; i <= 100; i++){
67
mat1.v[0][i] = freq[i];
68
for(int j = 1; j < i; j++){
69
mat1.v[0][i] = add(mat1.v[0][i], mul(mat1.v[0][j], freq[i - j]));
70
}
71
}
72
for(int i = 0; i <= 100; i++) mat2.v[i + 1][i] = 1;
73
for(int i = 0; i <= 100; i++) mat2.v[i][100] = freq[100 - i + 1];
74
75
mat2.v[0][102] = 1; mat2.v[102][102] = 1;
76
mat1 = mat1 * power(mat2, k + 1);
77
cout <<mat1.v[0][102] << endl;
78
}
79
80
int main() {
81
Speed();
82
int tc = 1;
83
//cin >> tc;
84
while (tc--) {
85
solve();
86
}
87
return 0;
88
}