Instantly share code, notes, and snippets.

# iRajul/card-sortingSecret Created Jun 14, 2014

What would you like to do?
Card Sorting - Longest Increasing Subsequence
 #include #include #include #include using namespace std; int BinarySearch(vector &arr,int *small,int n, int value) { int low = 0; int high = n-1; int mid; while (low < high) { mid = low + ((high - low) / 2); //! if array's mid value is greater then search value then select //! high as mid , this is where we are making it a ceil binary search if (arr[small[mid]] > value) high = mid; else if (arr[small[mid]] < value) low = mid + 1; else return mid;// found } return low;// not found } //! function to print longest Increasing Subsequence with nlog(n) complexity int LIS(vector &arr, int n) { int *small = new int[n]; int size = 0; for(int i=0 ; i=than X, //! and change it to X. Here parent[indexOfX] = S[index - 1]. else if(arr[i] <= arr[small[size]]) { int pos = BinarySearch(arr,small,size+1,arr[i]); small[pos] = i; } //! parent[indexOfX] = Last Element Of S else { size = size+1; small[size] = i; } } delete [] small; return (size+1); } int matrix[4][100]; int main( ) { int n,c; //Get Numbers of different colors and number cin>>c>>n; vectorv(n*c); vector color; vector number; //Get color and its corresponding number for(int i = 0;i>col>>num; color.push_back(col); number.push_back(num); } //per is used to do permutation of given number of colors vector per; for(int i=0; i