The maximum set
Practice
2.8 (5 votes)
Dynamic programming
Algorithms
C++
Introduction to dynamic programming 1
Problem
48% Success 1137 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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 \(1 \le i,j \le N\).
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
\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 1 \le A[i] \le 10^6\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
41 votes
Tags:
AlgorithmsDynamic ProgrammingGreedy Algorithms
Points:30
3 votes
Tags:
AlgorithmsDynamic ProgrammingDynamic programmingEasy
Points:30
9 votes
Tags:
PrefixDynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1
Editorial