All pastes #2104578 Raw Edit

history grading-111

public text v1 · immutable
#2104578 ·published 2012-01-20 17:48 UTC
rendered paste body
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>arr;
int dp[25];
map<int,int>mp;
int lis(int pos)
{
    if(dp[pos]!=0) return dp[pos];
    dp[pos]=1;
    int i=0,v=0;
    for(i=0;i<pos;i++)
    {
        if(arr[i]<arr[pos])//if ith element actually occurs in the main list before currrent then call lis of ith elemtent
        {
            v=lis(i)+1;
        }else{
                v=lis(i);
               }
        dp[pos]=max(v,dp[pos]);
    }
    return dp[pos];
}
int main()
{
    int i=0,n=0,x=0,max=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        mp[x]=i;//mapping the position of the elements
    }
    while(cin>>x)
    {
        arr.clear();
        dp[0]=0;
        x=mp[x];
        arr.push_back(x);
         for(i=1;i<n;i++)
        {
            cin>>x;
            x=mp[x];
            arr.push_back(x);//storing the position of the elements to check  for disorder
            dp[i]=0;
        }
        max=lis(n-1);
        cout<<max<<endl;
    }

    return 0;
}