Guest User

Untitled

a guest
Oct 2nd, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | Source Code | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef pair<int,int> ii;
  5. int idx = 1, n, m, a[105];
  6. const int mod = 1e9+7;
  7. struct mat{
  8. int a[105][105];
  9. mat(){
  10. memset(a,0,sizeof(a));
  11. }
  12. mat operator*(mat other){
  13. mat res;
  14. for (int i = 1; i <= idx; i++){
  15. for (int j = 1; j <= idx; j++){
  16. for (int k = 1; k <= idx; k++){
  17. (res.a[i][j] += 1ll*a[i][k]*other.a[k][j]%mod)%=mod;
  18. }
  19. }
  20. }
  21. return res;
  22. }
  23. void print(){
  24. vector<ii> res;
  25. for (int i = 1; i <= idx; i++){
  26. for (int j = 1; j <= idx; j++){
  27. cout << a[i][j] << " ";
  28. if (a[i][j]) res.push_back({i,j});
  29. }
  30. cout << "\n";
  31. }
  32. for (auto x: res) cout << x.first << " " << x.second << " = " << a[x.first][x.second]<< "\n";
  33. cout << "\n";
  34. }
  35. };
  36. mat power(mat a, int n){
  37. mat res;
  38. for (int i = 1; i <= idx; i++) res.a[i][i] = 1;
  39. while (n>0){
  40. if (n%2) res = res*a;
  41. a = a*a;
  42. n /= 2;
  43. }
  44. return res;
  45. }
  46.  
  47. int main(){
  48. freopen("nequation.inp","r",stdin);
  49. freopen("nequation.out","w",stdout);
  50. cin >> n >> m;
  51. int sum = 0;
  52. for (int i = 1; i <= n; i++){
  53. cin >> a[i];
  54. sum += a[i];
  55. }
  56. mat matA;
  57.  
  58. matA.a[1][1] = 1;
  59. int u = 1;
  60. for (int i = 1; i <= n; i++){
  61. matA.a[u][++idx] = 1;
  62. int v = idx;
  63. for (int j = 1; j < a[i]; j++) matA.a[idx][++idx] = 1;
  64. matA.a[idx][v] = 1;
  65. u = v;
  66. }
  67. auto res = power(matA,m-sum+n);
  68. // res.print();
  69. // cout << u << "\n";
  70. cout << res.a[1][u];
  71.  
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment