#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
class Solution
{
public:
int lengthOfLIS(std::vector<int> &);
int max(int, int);
std::string print(std::vector<int> const &);
};
int Solution::max(int a, int b)
{
return a < b ? b : a;
}
std::string Solution::print(std::vector<int> const &input)
{
std::stringstream ss;
for (int i = 0; i < input.size(); i++)
ss << input.at(i) << ' ';
return ss.str();
}
int Solution::lengthOfLIS(std::vector<int> &nums)
{
int n = nums.size();
if (n == 0)
return 0;
int list[n];
std::fill_n(list, n, 1);
//list[0] = 1;
for (int i = 1; i < n; i++)
{
int min_val = nums[i];
for (int j = i - 1; j > -1; j--)
{
if (nums[j] < nums[i] && nums[j] < min_val)
{
list[i]++;
min_val = nums[j];
}
}
}
int ans = 1;
for(int i = 0; i < n; i++)
ans = max(ans, list[i]);
return ans;
}
int main()
{
std::vector<int> Input0 { 10, 9, 2, 5, 3, 7, 101, 18 },
Input1 { 10, 19, 2, 5, 3, 7, 101, 18 },
Input2 { 10, 9, 12, 5, 3, 7, 101, 18 },
Input3 { 10, 9, 2, 15, 3, 7, 101, 18 },
Input4 { 10, 9, 2, 5, 13, 7, 101, 18 },
Input5 { 10, 9, 2, 5, 3, 17, 101, 18 },
Input6 { 10, 9, 2, 5, 13, 7, 10, 18 },
Input7 { 10, 9, 2, 5, 13, 7, 101, 180 };
Solution solution;
std::cout << solution.print(Input0) << "\t|\t" << solution.lengthOfLIS(Input0) << std::endl;
std::cout << solution.print(Input1) << "\t|\t" << solution.lengthOfLIS(Input1) << std::endl;
std::cout << solution.print(Input2) << "\t|\t" << solution.lengthOfLIS(Input2) << std::endl;
std::cout << solution.print(Input3) << "\t|\t" << solution.lengthOfLIS(Input3) << std::endl;
std::cout << solution.print(Input4) << "\t|\t" << solution.lengthOfLIS(Input4) << std::endl;
std::cout << solution.print(Input5) << "\t|\t" << solution.lengthOfLIS(Input5) << std::endl;
std::cout << solution.print(Input6) << "\t|\t" << solution.lengthOfLIS(Input6) << std::endl;
std::cout << solution.print(Input7) << "\t|\t" << solution.lengthOfLIS(Input7) << std::endl;
return 0;
}