Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef unsigned long long ll;
  6. const ll MOD = 1e9+7;
  7.  
  8. ll lis(int arr[], int N)
  9. {
  10.     ll table[N];
  11.     ll table_count[N];
  12.  
  13.     memset(table, 0, sizeof(table));
  14.     memset(table_count, 0, sizeof(table_count));
  15.  
  16.     for (int i=0; i<N; i++) {
  17.         for (int j=0; j<i; j++) {
  18.             if (arr[i] > arr[j]) {
  19.                 table[i] = max(table[i], table[j]+1);
  20.                 table_count[i] = (table_count[i] + 1) % MOD;
  21.             }
  22.         }
  23.     }
  24.  
  25.     return table_count[N-1];
  26. }
  27.  
  28. int solve(int arr[], int N)
  29. {
  30.     int total=0;
  31.  
  32.     for (int i=0; i<N+1; i++) {
  33.         for (int j=0; j<i; j++) {
  34.  
  35.             int subN = i-j;
  36.             int subArr[subN];
  37.  
  38.             for (int k=j; k<i; k++)
  39.                 subArr[k-j] = arr[k];
  40.  
  41.             ll res = lis(subArr, subN);
  42.             total += res;
  43.  
  44.             if (subN > 1 || res != subN)
  45.                 total += subN;
  46.         }
  47.     }
  48.    
  49.     return total;
  50. }
  51.  
  52. int main()
  53. {
  54.     int N;
  55.     cin >> N;
  56.    
  57.     int arr[N];
  58.     for (int i=0; i<N; i++) cin >> arr[i];
  59.  
  60.     cout << solve(arr, N) << endl;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement