Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ll;
- const ll MOD = 1e9+7;
- ll lis(int arr[], int N)
- {
- ll table[N];
- ll table_count[N];
- memset(table, 0, sizeof(table));
- memset(table_count, 0, sizeof(table_count));
- for (int i=0; i<N; i++) {
- for (int j=0; j<i; j++) {
- if (arr[i] > arr[j]) {
- table[i] = max(table[i], table[j]+1);
- table_count[i] = (table_count[i] + 1) % MOD;
- }
- }
- }
- return table_count[N-1];
- }
- int solve(int arr[], int N)
- {
- int total=0;
- for (int i=0; i<N+1; i++) {
- for (int j=0; j<i; j++) {
- int subN = i-j;
- int subArr[subN];
- for (int k=j; k<i; k++)
- subArr[k-j] = arr[k];
- ll res = lis(subArr, subN);
- total += res;
- if (subN > 1 || res != subN)
- total += subN;
- }
- }
- return total;
- }
- int main()
- {
- int N;
- cin >> N;
- int arr[N];
- for (int i=0; i<N; i++) cin >> arr[i];
- cout << solve(arr, N) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement