Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
dynamic_programming Namespace Reference

Dynamic Programming algorithms. More...

Functions

uint64_t LIS (const std::vector< uint64_t > &a, const uint32_t &n)
 Calculate the longest increasing subsequence for the specified numbers. More...
 

Detailed Description

Dynamic Programming algorithms.

Dynamic programming algorithms.

for std::vector

Dynamic Programming algorithm.

Dynamic Programming Algorithms.

for assert for IO operations for std::string library for std::vector STL library

for assert for std::max for io operations

Dynamic Programming algorithms

for assert for std::max for IO operations

Dynamic Programming algorithms

for assert for IO operations

Dynamic Programming algorithms

Function Documentation

◆ LIS()

uint64_t dynamic_programming::LIS ( const std::vector< uint64_t > &  a,
const uint32_t &  n 
)

Calculate the longest increasing subsequence for the specified numbers.

Parameters
athe array used to calculate the longest increasing subsequence
nthe size used for the arrays
Returns
the length of the longest increasing subsequence in the a array of size n
39 {
40 std::vector<int> lis(n);
41 for (int i = 0; i < n; ++i) {
42 lis[i] = 1;
43 }
44 for (int i = 0; i < n; ++i) {
45 for (int j = 0; j < i; ++j) {
46 if (a[i] > a[j] && lis[i] < lis[j] + 1) {
47 lis[i] = lis[j] + 1;
48 }
49 }
50 }
51 int res = 0;
52 for (int i = 0; i < n; ++i) {
53 res = std::max(res, lis[i]);
54 }
55 return res;
56}
T max(T... args)
Here is the call graph for this function: