Skip to content

Instantly share code, notes, and snippets.

View vivan188's full-sized avatar

Vivan Singh Chouhan vivan188

View GitHub Profile
@vivan188
vivan188 / dp_sol.cpp
Created March 19, 2021 12:06
Solution to LIS using DP
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn], lis[maxn], lds[maxn];
int l[maxn], r[maxn], lcnt[maxn];
int main(){
int n;
cin >> n;
int longest_increasing_subsequence(int arr[], int N)
{
int lis[N]
for(i = 0 to N-1)
lis[i] = 0
lis[0] = 1
for(i = 1 to N-1)
{
for(j = 0 to i-1)
{
@vivan188
vivan188 / BruteForce.cpp
Created March 19, 2021 11:45
LIS_BruteForce
#include <bits/stdc++.h>
int _lis( int arr[], int n, int *max_ref)
{
if (n == 1)
return 1;
int res, max_ending_here = 1;
for (int i = 1; i < n; i++)
{
res = _lis(arr, i, max_ref);
if (arr[i-1] < arr[n-1] && res + 1 > max_ending_here)