fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define Samurai ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
  5. #define pr_g priority_queue<pair<ll,int>, vector<pair<ll,int>>,greater<pair<ll,int>>>
  6. int dx [] = {0, 0, 1, -1, 1, 1, -1, -1};
  7. int dy [] = {-1, 1, 0, 0, -1, 1, 1, -1};
  8. char dir [] = {'>', '<', '^', 'v'};
  9. int Lx[] = {2, 2, -2, -2, 1, 1, -1, -1};
  10. int Ly[] = {1, -1, 1, -1, 2, -2, 2, -2};
  11. const double PI = acos(-1.0);
  12. #define el '\n'
  13. const ll mod = 1e9 + 7, N = 2e5 + 5, OO = 0x3f3f3f3f;
  14. ll n, a[N], dp[N];
  15. ll rec (int i) {
  16. ll &ret = dp[i];
  17. if (~ret)
  18. return ret;
  19. ret = 1;
  20. for (int j = i + 1; j < n; j++)
  21. if (a[i] < a[j]) {
  22. ret += (rec(j)) % mod;
  23. ret %= mod;
  24. }
  25. return ret;
  26. }
  27.  
  28. void solve() {
  29. cin >> n;
  30. for (int i = 0; i < n; i++)
  31. cin >> a[i];
  32. memset(dp, -1, sizeof dp);
  33. ll sum = 0;
  34. for (int i = 0; i < n; i++) {
  35. sum += rec(i) % mod;
  36. sum %= mod;
  37. }
  38. cout << sum;
  39.  
  40. }
  41.  
  42. int main() { Samurai
  43. int _t = 1; //cin >> _t;
  44. for (int i = 1; i <= _t; i++){
  45. solve();
  46. }
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5912KB
stdin
Standard input is empty
stdout
Standard output is empty