-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathlis-pair.C
More file actions
42 lines (34 loc) · 709 Bytes
/
lis-pair.C
File metadata and controls
42 lines (34 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<stdio.h>
#include<stdlib.h>
int max(int a,int b)
{
return a > b ? a : b;
}
int max_incre(int array[100][2],int n)
{
int count[5],i,j,maxi = 1;
for(i=0;i<n;i++)
count[i] = 1;
/*
resulting array for the input
array : [(5,24)(39,60)(15,28)(27,40)(50,90)]
count : [ 1 2 1 2 3 ]
*/
//
for(i=1;i<n;i++)
for(j=0;j<n;j++)
{
if(array[i][0]>array[j][1])
count[i] = max(count[i],count[j]+1);
if(count[i] > maxi)
maxi = count[i];
}
return maxi;
}
int main()
{
int i,n,array[][2]={{5,24},{39,60},{15,28},{27,40},{50,90}};
n = sizeof(array)/sizeof(array[0]); //returns no of elements in the array
printf("Lis = %d\n",max_incre(array,n));
return 0;
}