Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <map>
- #include <unordered_map>
- #define task "DREAM"
- #define int int_fast32_t
- using namespace std;
- using ll = int_fast64_t;
- using ld = long double;
- const int N = 1e2 + 2;
- const ll mod = 1e9 + 7;
- int sz;
- struct Matrix{
- ll a[N][N];
- Matrix() {fill_n(&a[0][0], N * N, 0);}
- Matrix operator * (const Matrix &m) {
- Matrix ans;
- for(int i = 1; i < sz; ++i)
- for(int j = 1; j < sz; ++j)
- for(int t = 1; t < sz; ++t){
- auto &v = ans.a[i][t];
- v += a[i][j] * m.a[j][t];
- if(v > mod || v < -mod)
- v %= mod;
- }
- return ans;
- }
- };
- Matrix Pow(Matrix &a, ll b){
- Matrix tmp;
- for(int i = 1; i < sz; ++i)
- tmp.a[i][i] = 1;
- for(; b > 0; b >>= 1){
- if(b & 1) tmp = tmp * a;
- a = a * a;
- }
- return tmp;
- }
- int n;
- ll k, s[N];
- int dp[N];
- template<class T>
- void read(T &x){
- register int c;
- x = 0;
- while((c = getchar()) && c < '0' || c > '9');
- for(; c >= '0' && c <= '9'; c = getchar())
- x = x * 10 + c - '0';
- }
- void Read(){
- read(n); read(k);
- for(int i = 1; i <= n; ++i){
- int d; read(d);
- ++s[d];
- sz = max(sz, d + 2);
- }
- }
- void Forces(){
- dp[0] = 1;
- for(ll i = 1; i <= k; ++i){
- for(int j = 1; j < sz; ++j)
- if(i >= j){
- dp[i] = (dp[i] + s[j] * dp[i - j] % mod ) % mod;
- if(i - j > 0)
- dp[i] = (dp[i] - s[j] * dp[i - j - 1]) % mod;
- }
- dp[i] = (dp[i] + dp[i - 1]) % mod;
- }
- cout << (dp[k] + mod) % mod;
- }
- void Solve(){
- Matrix ans, cur;
- //memset(dp, 0, sizeof dp);
- dp[0] = 1;
- for(int i = 1; i < sz; ++i){
- cur.a[sz - 1][sz - i] = (cur.a[sz - 1][sz - i] + s[i]) % mod;
- cur.a[sz - 1][sz - i - 1] = (cur.a[sz - 1][sz - i - 1] - s[i]) % mod;
- for(int j = 1; j <= i; ++j){
- dp[i] = (dp[i] + s[j] * dp[i - j] % mod ) % mod;
- if(i != j)
- dp[i] = (dp[i] - s[j] * dp[i - j - 1]) % mod;
- }
- dp[i] = (dp[i] + dp[i - 1]) % mod;
- ans.a[i][1] = dp[i];
- cur.a[i][i + 1] = 1;
- }
- ++cur.a[sz - 1][sz - 1];
- cur = Pow(cur, k - 1ll) * ans;
- cout << (cur.a[1][1] + mod) % mod;
- }
- signed main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0); if(fopen(task".INP", "r"))
- freopen(task".INP", "r", stdin),
- freopen(task".OUT", "w", stdout);
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment