Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <unordered_map>
- #define task "DREAM"
- using namespace std;
- using ll = long long;
- using ld = long double;
- const int N = 1e2 + 10;
- const ll mod = 1e9 + 7;
- int sz;
- struct Matrix{
- ll a[N][N];
- Matrix() {memset(a, 0, sizeof a);}
- 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)
- ans.a[i][j] = (ans.a[i][j] + a[i][t] * m.a[t][j] % mod) % 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;
- /*for(int i = 1; i < sz; ++i)
- for(int j = 1; j < sz; ++j)
- cout << tmp.a[i][j] << (j == sz - 1 ? "\n" : " ");
- cout << "\n";*/
- }
- a = a * a;
- }
- return tmp;
- }
- int n;
- ll k;
- ll dp[100002], ans;
- unordered_map<int, ll> s;
- 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((int)sz, d + 3);
- }
- }
- void Forces(){
- dp[0] = 1;
- for(ll i = 1; i <= k; ++i){
- for(auto j : s)
- if(i >= j.first){
- dp[i] = (dp[i] + j.second * dp[i - j.first] % mod ) % mod;
- if(i - j.first > 0)
- dp[i] = (dp[i] - j.second * dp[i - j.first - 1]) % mod;
- }
- dp[i] = (dp[i] + dp[i - 1]) % mod;
- ans = (ans + dp[i]) % mod;
- }
- cout << (dp[k] + mod) % mod;
- }
- void Solve(){
- Matrix ans, cur;
- memset(dp, 0, sizeof dp);
- dp[0] = 1;
- for(ll i = 1; i < sz; ++i){
- for(auto j : s)
- if(i >= j.first){
- dp[i] = (dp[i] + j.second * dp[i - j.first] % mod ) % mod;
- if(i - j.first > 0)
- dp[i] = (dp[i] - j.second * dp[i - j.first - 1]) % mod;
- }
- dp[i] = (dp[i] + dp[i - 1]) % mod;
- }
- for(int i = 1; i < sz; ++i)
- ans.a[i][1] = dp[i],
- cur.a[i][i + 1] = 1;
- for(auto j : s){
- cur.a[sz - 1][sz - j.first] = (cur.a[sz - 1][sz - j.first] + j.second) % mod;
- cur.a[sz - 1][sz - j.first - 1] = (cur.a[sz - 1][sz - j.first - 1] - j.second) % mod;
- }
- ++cur.a[sz - 1][sz - 1];
- cur = Pow(cur, k - 1ll);
- cur = cur * ans;
- cout << (cur.a[1][1] + mod) % mod;
- }
- signed main(){
- ios::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();
- if(k <= 1e3)
- Forces();
- // cout << "\n";
- else
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment