-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive-LIS.cpp
More file actions
37 lines (29 loc) · 807 Bytes
/
recursive-LIS.cpp
File metadata and controls
37 lines (29 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
map < pair<int,int>, int > mp;
int n,temp;
int LIS(int num,int idx){
if (idx == v.size()) return 0;
pair<int,int>pr = make_pair(num,idx);
if (mp.count(pr)){
cout << pr.first << ' ' << pr.second << endl;
return mp.at(pr);
}
int left,right;
if (v[idx] > num ) left = LIS(v[idx],idx+1)+1;
right = LIS(num,idx+1);
if (v[idx] > num) mp.insert(make_pair(pr,max(left,right)));
else mp.insert(make_pair(pr,right));
return mp.at(pr);
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
scanf("%d",&n);
for (int i = 0;i<n;i++){
scanf("%d",&temp);
v.push_back(temp);
}
printf("%d\n",LIS(-99999,0));
return 0;
}