#C6156. Maximum Dissimilar Photos
Maximum Dissimilar Photos
Maximum Dissimilar Photos
You are given a set of n photos along with an n x n similarity matrix. The value at the i
-th row and j
-th column represents the similarity score between photo i
and photo j
. You are also given an integer threshold S.
Your task is to choose the largest subset of these photos such that for every pair of chosen photos i and j, the similarity score satisfies \[ \text{similarity}_{ij} \leq S \] In other words, no two selected photos should have a similarity score that exceeds S.
Input and Output details:
The input is read from stdin and the output should be written to stdout.
Determine and print the maximum number of photos that can be selected that meet the above criterion.
inputFormat
The first line contains two integers n
and S
, where n
is the number of photos and S
is the similarity threshold.
The next n
lines each contain n
integers, representing the similarity matrix. The j
-th number in the i
-th line represents the similarity score between photo i
and photo j
.
Note: It is guaranteed that the matrix is symmetric and the diagonal elements are zero.
outputFormat
Output a single integer representing the maximum number of photos that can be chosen such that for every pair of selected photos, their similarity score does not exceed S
.
3 5
0 6 4
6 0 3
4 3 0
2