fork download
  1. // بسم الله الرحمن الرحيم
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. template<typename T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto& i : v) os << i << ' '; return os; }
  7. template<typename T> istream& operator>>(istream& is, vector<T>& v) { for (auto& i : v) is >> i; return is; }
  8.  
  9. #define FreePalestine ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  10.  
  11. #define endl '\n'
  12. #define int long long
  13. #define ull unsigned long long
  14. #define vi vector<int>
  15. #define vvi vector<vi>
  16. #define pi pair<int, int>
  17. #define all(a) a.begin(), a.end()
  18. #define all_r(a) a.rbegin(), a.rend()
  19.  
  20. const int N = 302, oo = 2e18, MOD = 1e9+7;
  21. int n, a[N], dp[N][N][N];
  22.  
  23. int ans(int i = 0, int mx = 0, int mx_2 = 0) {
  24. if (i >= n)
  25. return 1;
  26.  
  27.  
  28. int& ret = dp[i][mx][mx_2];
  29.  
  30. if (~ret)
  31. return ret;
  32.  
  33. ret = 0;
  34.  
  35. ret += ans(i+1, mx, mx_2);
  36. if (ret >= MOD)
  37. ret -= MOD;
  38.  
  39. if (a[i] >= mx_2) {
  40. if (a[i] > mx) {
  41. mx_2 = mx;
  42. mx = a[i];
  43. }
  44. else if (a[i] != mx && a[i] > mx_2) {
  45. mx_2 = a[i];
  46. }
  47. ret += ans(i+1, mx, mx_2);
  48.  
  49. if (ret >= MOD)
  50. ret -= MOD;
  51.  
  52. }
  53.  
  54. return ret;
  55. }
  56.  
  57. void solve() {
  58. cin >> n;
  59. for (int i = 0; i < n; i++) {
  60. cin >> a[i];
  61. }
  62. memset(dp, -1, sizeof dp);
  63.  
  64. cout << ans() << endl;
  65. }
  66.  
  67.  
  68. signed main() {
  69. FreePalestine;
  70. // #ifndef ONLINE_JUDGE
  71. // freopen("input.txt", "r", stdin);
  72. // freopen("output.txt", "w", stdout);
  73. // #endif
  74. int t; t = 1;
  75. cin >> t;
  76. while (t--) solve();
  77. return 0;
  78. }
Success #stdin #stdout 0.04s 218844KB
stdin
Standard input is empty
stdout
1