-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintAllLIS.cpp
65 lines (46 loc) · 1.38 KB
/
PrintAllLIS.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std ;
#define ff first
#define ss second
int main(){
int n ; cin>> n ;
int arr[n] ;
for(int i = 0 ; i<n ; i++ ) cin>>arr[i] ;
unordered_map<int, pair<int,vector<vector<int>> > > dp ;
int maxi = 1 ;
for(int i = 0 ; i<n ; i++){
dp[i].ff = 1 ;
for(int j = 0 ; j<= i-1 ; j++){
if(arr[j] < arr[i]){
dp[i].ff = max( dp[i].ff , dp[j].ff + 1) ;
}
}
for(int j = i-1 ; j>=0 ; j--){
if(arr[j] < arr[i] and (dp[i].ff == (1 + dp[j].ff )) ) {
for(auto &vec : dp[j].ss){
vector<int> temp = vec ;
temp.push_back(arr[i]) ;
dp[i].ss.push_back(temp) ;
}
}
}
if(dp[i].ff == 1){
dp[i].ss.push_back({arr[i]}) ;
}
maxi = max(maxi, dp[i].ff) ;
}
cout<<maxi<<endl;
for(int i = 0 ; i<n ; i++){
if(dp[i].ff == maxi ){
for(auto &vec : dp[i].ss){
int n = vec.size() ;
for(int i = 0 ; i<n ; i++){
cout<<vec[i];
if(i != n-1) cout<<" -> " ;
}
cout<<endl;
}
}
}
return 0 ;
}