-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path104.cpp
62 lines (54 loc) · 1.56 KB
/
104.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
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int getLongestIncSub(const std::vector<int> &sequence, size_t index, vector< vector< int > > &sub) {
if(index == 0) {
sub.push_back(std::vector<int>{sequence[0]});
return 1;
}
size_t longestSubSeq = getLongestIncSub(sequence, index - 1, sub);
vector< vector< int > > tmpSubSeq;
for(vector< int > &subSeq : sub) {
if(subSeq[subSeq.size() - 1] < sequence[index]) {
std::vector<int> newSeq(subSeq);
newSeq.push_back(sequence[index]);
longestSubSeq = std::max(longestSubSeq, newSeq.size());
tmpSubSeq.push_back(newSeq);
}
}
std::copy(tmpSubSeq.begin(), tmpSubSeq.end(),
std::back_insert_iterator<std::vector<std::vector<int>>>(sub));
return longestSubSeq;
}
int getLongestIncSub(const std::vector<int> &sequence) {
std::vector<std::vector<int>> sub;
return getLongestIncSub(sequence, sequence.size() - 1, sub);
}
int main()
{
int n,t;
cin>>n>>t;
vector< int > v(n);
for (int i=0; i<n; i++){
cin>>v[i];
}
vector< int > c = v;
for (int i=0; i<t-1; i++)
v.insert(v.end(), c.begin(), c.end());
cout<<getLongestIncSub(v)<<endl;
//
// if (5<t){
// int a1 = getLongestIncSub(v);
// v.insert(v.end(), c.begin(), c.end());
// int a2 = getLongestIncSub(v);
// int d = a2 - a1;
// int l = t - 5;
// cout<<a1 + d*l<<endl;
// }else{
// cout<< getLongestIncSub( v)<<endl;
// }
return 0;
}
// 6
// 3 1# 4 2# 3# 1 4# 2 3 1 4# 2 3 1 4# 2 3 1 4# 2 3 1 4# 2