The maximum set

2.8

5 votes
Dynamic Programming, Algorithms, C++, Introduction to Dynamic Programming 1
Problem

You are given an array A of N integer elements. A pair of elements (i,j) is said to be an inversion if A[i]>A[j] and i<j for all 1i,jN.

Using this array A, you create an undirected graph G of N vertices. For each inversion pair (i,j), there exists an edge between vertex i and j.

Find the maximum size of set S consisting of vertices from graph G such that there exists an edge between every pair of vertices present in S.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N.
  • The second line of each test case contains space-separated integers denoting array A.

Output format

For each test case, print the maximum size of set S in a new line.

Constraints

1T101N1051A[i]106

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Graph G is a complete graph, i.e. there exists an edge between every pair of vertex.

Thus, maximum size of set S is 4.

Editor Image

?