-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIS and LowerBound
More file actions
50 lines (50 loc) · 868 Bytes
/
LIS and LowerBound
File metadata and controls
50 lines (50 loc) · 868 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
43
44
45
46
47
48
49
50
#pragma warning(disable:4996)
#include<cstdio>
int mylower_bound(int *arr,int n,int key)
{
int start=0;
int end=n;
int mid;
while(start<end)
{
mid=(start+end)/2;
if(arr[mid]<key)
{
start=mid+1;
}
else
{
end=mid;
}
}
return end;
}
int main(void)
{
/*
int n, arr[1000000],ans[1000000];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
*/
int arr[6]={10,20,10,30,20,50};
int ans[6];
ans[0]=arr[0];
int anslength=1;
for(int i=1;i<6;i++)
{
int tmp=mylower_bound(ans,anslength,arr[i]);
if(tmp>=anslength)
{
ans[tmp]=arr[i];
anslength++;
}
else
{
ans[tmp]=arr[i];
}
}
printf("%d",anslength);
}