#include <iostream>
using namespace std;
#include <iostream>
#include <vector>
void prt(vector<int>& arr, string msg = "") {
cout << msg << " ";
for (auto i: arr) {
cout << i << " ";
}
cout << endl;
}
void calc_LIS(vector<int>& D) {
vector< vector<int> > L(D.size()); // The longest increasing subsequence ends with D[i]
L[0].push_back(D[0]);
for (int i=1; i<D.size(); i++) {
for(int j=0; j<i; j++) {
if ( (D[j] < D[i]) && ( L[i].size() < L[j].size() ) ) {
L[i] = L[j];
}
}
L[i].push_back(D[i]);
}
for (auto x: L) {
prt(x);
}
}
int main() {
int a[] = {3, 4, 6, 4, 5, 1};
vector<int> arr(a, a + sizeof(a)/sizeof(a[0]));
//prt(arr, "Data In:");
calc_LIS(arr);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CgoKdm9pZCBwcnQodmVjdG9yPGludD4mIGFyciwgc3RyaW5nIG1zZyA9ICIiKSB7Cgljb3V0IDw8IG1zZyA8PCAiICI7Cglmb3IgIChhdXRvIGk6IGFycikgewoJCWNvdXQgPDwgaSA8PCAiICI7Cgl9Cgljb3V0IDw8IGVuZGw7Cn0KCgp2b2lkIGNhbGNfTElTKHZlY3RvcjxpbnQ+JiBEKSB7Cgl2ZWN0b3I8IHZlY3RvcjxpbnQ+ID4gTChELnNpemUoKSk7ICAvLyBUaGUgbG9uZ2VzdCBpbmNyZWFzaW5nIHN1YnNlcXVlbmNlIGVuZHMgd2l0aCBEW2ldCgogICBMWzBdLnB1c2hfYmFjayhEWzBdKTsKCglmb3IgKGludCBpPTE7IGk8RC5zaXplKCk7IGkrKykgewoJCWZvcihpbnQgaj0wOyBqPGk7IGorKykgewoJCQlpZiAoIChEW2pdIDwgRFtpXSkgJiYgKCBMW2ldLnNpemUoKSA8IExbal0uc2l6ZSgpICkgKSB7CgkJCQlMW2ldID0gTFtqXTsgIAkJCQkKCQkJf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