Skip to content

Instantly share code, notes, and snippets.

@maksadbek
Created September 12, 2013 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maksadbek/6540801 to your computer and use it in GitHub Desktop.
Save maksadbek/6540801 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> inputs;
int input;
while(cin>>input)
inputs.push_back(input);
int length = inputs.size();
length = inputs.size();
vector<int> A(length, 1);
vector<int> tmps(length, 0);
for(int i=1; i< length; i++)
for(int j=0; j< i; j++){
int tmp = inputs[j] - inputs[i];
if(tmp != 0 && tmp*tmps[j] <= 0 && A[j] + 1 > A[i]){
A[i] = A[j] + 1;
tmps[i] = tmp;
}
}
cout<<A[length-1];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment