TopCoder problem "PaternityScandal" used in TCHS SRM 64 (Division I Level One)



Problem Statement

    

Your lab has been doing a series of tests to a population of adults and children that may or may not be related. Things were going OK until the family data was lost. The family data contained information about which adults were the parents of which children, and which female adults were the spouses of which male adults.



However, the lab still has the genetic profile for each person, along with personality test results for all the adults. Using this information, the lab was able to produce the following three tables, each given as a String[]:



  • femaleGeneticTest: The j-th character of the i-th element of femaleGeneticTest is 'Y' if the i-th female adult is genetically compatible with the j-th child. Otherwise, it is 'N'.
  • maleGeneticTest: The j-th character of the i-th element of maleGeneticTest is 'Y' if the i-th male adult is genetically compatible with the j-th child. Otherwise, it is 'N'.
  • personalityTest: The j-th character of the i-th element of personalityTest is 'Y' if the personality of the i-th male adult is compatible with the personality of the j-th female adult.


Your task is to try to rebuild the family data from these tables. The lab has defined a family as one female adult and one male adult whose personalities are compatible, along with 0 or more children, each of which is genetically compatible with both adults. Given the information above, return the size of the largest possible family, or return 0 if there are no families.

 

Definition

    
Class:PaternityScandal
Method:getFamily
Parameters:String[], String[], String[]
Returns:int
Method signature:int getFamily(String[] femaleGeneticTest, String[] maleGeneticTest, String[] personalityTest)
(be sure your method is public)
    
 

Constraints

-The input will represent data for F females, M males and C children, with F, M and C being between 1 and 50, inclusive.
-femaleGeneticTest will contain exactly F elements.
-maleGeneticTest will contain exactly M elements.
-personalityTest will contain exactly M elements.
-Each element of femaleGeneticTest will contain exactly C characters.
-Each element of maleGeneticTest will contain exactly C characters.
-Each element of personalityTest will contain exactly F characters.
-Each character of femaleGeneticTest will be 'Y' or 'N'.
-Each character of maleGeneticTest will be 'Y' or 'N'.
-Each character of personalityTest will be 'Y' or 'N'.
 

Examples

0)
    
{"NYY"}
{"YNY"}
{"Y"}
Returns: 3
There is one female adult, one male adult and three kids. The adults' personalities are compatible, so they could be a couple. However, only kid 2 could be their child because he is the only child genetically compatible with both adults.
1)
    
{"NYYYN","YYYYY"}
{"NNYNY","YYYYN"}
{"YN","NY"}
Returns: 6
In this case, there are two possible couples (male 0 with female 0 and male 1 with female 1) and 5 children. Only one child is genetically compatible with both members of couple 0, while four children are genetically compatible with couple 1. The largest possible family contains 6 members, composed of male adult 1, female adult 1 and kids 0 to 3.
2)
    
{"YYYYYYYYY","YYYYYYYYY","YYYYYYYYY","YYYYYYYYY"}
{"YYYYYYYYY","YYYYYYYYY","YYYYYYYYY"}
{"NNNN","NNNN","NNNN"}
Returns: 0
There are four females, three males and nine children. All children are genetically compatible with every adult. However, no two adults of opposite sex have compatible personalities. This means no families can be formed, so the answer is 0.
3)
    
{"YYYYY","YNYNY","YYYNN"}
{"NNNNN","NYNYN","NNNYY"}
{"YNN","NYN","NNY"}
Returns: 2
A single couple with no children is considered to be a valid family.
4)
    
{"NNNN","NYNY","NNYY","YNYN","YYNN"}
{"YYYY","NNYN","YNYY"}
{"YNNNN","NYYYY","NYYYN"}
Returns: 4
5)
    
{"YYYNN","NNYNY","NNYYN","YYYYN","YNYYN","NYYNY"}
{"YYNNY","NNNYY","YYYNN","NNNNN","YNNYN","NYNNY","YNNYY"}
{"NNNNNN","NYYNNY","NYNNNY","NYNNYN","YNYNNN","YYNNYN","NYYYNY"}
Returns: 4

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13533&pm=10198

Writer:

vexorian

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration