I've been trying to solve this Dynamic Programming problem which states a following. You are given an integer N, followed by N integers. Find the longest increasing subsequence possible within the sequence given. I should also mention that the numbers don't have to be consecutive.
The program I wrote doesn't change the value of it, it just leaves everything as number 1. (you'll see what I mean in the code)
#include<iostream>
#include<queue>
usingnamespace std;
constint MAXS = 1000000;
int longestSeq[MAXS];
int allNumbers[MAXS];
int main(){
int n;
cin>>n;
for (int i=0; i<n; i++){
cin>>allNumbers[i];
}
for (int i=n-1; i>=0; i--){
longestSeq[i] = 1;
for (int j=0; j<i; j++){
/*Here it is supposed to change the value of longestSeq[i], but it doesn't */
if (allNumbers[i]>allNumbers[j]){
longestSeq[i] = max(longestSeq[i], 1+longestSeq[j]);
}
}
}
sort(longestSeq, longestSeq+n);
cout<<longestSeq[n-1];
}