Skip to content

Instantly share code, notes, and snippets.

@ch-hristov
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save ch-hristov/82606677bebf8b633220 to your computer and use it in GitHub Desktop.

Select an option

Save ch-hristov/82606677bebf8b633220 to your computer and use it in GitHub Desktop.
Largest increasing subset
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
int integers[n];
for (int i = 0; i < n; i++)
cin >> integers[i];
int j[n];//n
for (int i = 0; i < n; i++){
j[i] = 1;
int max = 1;
for (int h = 0; h < i; h++){
if (integers[i] >= integers[h]){
if (j[h] + 1 > max)
max = j[h] + 1;
}
}
j[i] = max;
}
cout << j[n - 1] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment