#include <iostream.h>
void main()
{
int i,j,a[14]={5,6,-6,-1,9,10,-5,-3,16,4,3,-4,-3,5};
int dp[14];
for(i=0;i<14;i++)
dp[i]=1;
for(i=1;i<14;i++)
for(j=0;j<i;j++)
if(a[j]<a[i] && dp[j]+1>dp[i])
dp[i]=dp[j]+1;
for(i=0;i<14;i++)
cout<<a[i]<<"\t"<<dp[i]<<endl;
}
- This state carries only data about the length of this sequence. Note that for i<j the state i is independent from j, i.e. doesn’t change when we calculate state j.
- https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/