TopCoder problem "TeamSelection" used in TCHS SRM 62 (Division I Level One)



Problem Statement

    You are a programming team coach, and your task is to put together the best possible team of three students. There are several students willing to join the team, and their ratings are given in the int[] ratings, where the i-th element is the rating of the i-th student. Unfortunately, some students cannot work together. You are given a String[] compatibility, where the j-th character of the i-th element is 'Y' if the i-th student and j-th student can work together, and 'N' otherwise. You must pick a team of three students such that everybody on the team can work with everybody else on the team, and the sum of their ratings is as high as possible. Return the sum of the team members' ratings, or -1 if it is impossible to pick such a team.
 

Definition

    
Class:TeamSelection
Method:selectBestTeam
Parameters:int[], String[]
Returns:int
Method signature:int selectBestTeam(int[] rating, String[] compatibility)
(be sure your method is public)
    
 

Constraints

-rating will contain between 3 and 50 elements, inclusive.
-Each element of rating will be between 1 and 1000, inclusive.
-compatibility will contain the same number of elements as rating.
-Each element of compatibility will contain exactly n characters, where n is the number of elements in compatibility.
-compatibility will contain only the characters 'Y' and 'N'.
-The i-th character of the j-th element of compatibility will be equal to the j-th character of the i-th element of compatibility.
-The i-th character of the i-th element of compatibility will be 'Y'.
 

Examples

0)
    
{1,2,3,4}
{"YYYY",
 "YYYY",
 "YYYY",
 "YYYY"}
Returns: 9
Every student can work together with every other student.
1)
    
{1,2,3}
{"YNN",
 "NYN",
 "NNY"}
Returns: -1
No team can be composed because there is no pair of students who can work together.
2)
    
{1,2,3,4}
{"YYNN",
 "YYNN",
 "NNYY",
 "NNYY"}
Returns: -1
3)
    
{750, 911, 451, 578, 337, 894, 549, 620, 509, 672, 465, 562, 138, 939, 113}
{"YYNYYYNYNYYNYNN",
 "YYNYNYNNYNNNYYY",
 "NNYNYNNNYNNYNNY",
 "YYNYYYYNYNNYYNN",
 "YNYYYNNNNYNYYNY",
 "YYNYNYYYYNYYNYY",
 "NNNYNYYYYYNYYYN",
 "YNNNNYYYYYNYYNN",
 "NYYYNYYYYNYYYYY",
 "YNNNYNYYNYNNNNY",
 "YNNNNYNNYNYYYNN",
 "NNYYYYYYYNYYNYY",
 "YYNYYNYYYNYNYYY",
 "NYNNNYYNYNNYYYY",
 "NYYNYYNNYYNYYYY"}
Returns: 2744

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7731

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13531&pm=7731

Writer:

FedorTsarev

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Brute Force