TopCoder problem "CarolsSinging" used in SRM 331 (Division I Level One , Division II Level Two)



Problem Statement

    

When the Christmas dinner is over, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though.

You are given a String[] lyrics. The j-th character of the i-th element of lyrics is 'Y' if the i-th person knows the j-th carol, and 'N' if he doesn't. Return the minimal number of carols that must be sung to allow everyone to sing at least once.

 

Definition

    
Class:CarolsSinging
Method:choose
Parameters:String[]
Returns:int
Method signature:int choose(String[] lyrics)
(be sure your method is public)
    
 

Constraints

-lyrics will contain between 1 and 30 elements, inclusive.
-Each element of lyrics will contain between 1 and 10 characters, inclusive.
-Each element of lyrics will contain the same number of characters.
-Each element of lyrics will contain only 'Y' and 'N' characters.
-Each element of lyrics will contain at least one 'Y' character.
 

Examples

0)
    
{"YN","NY"}
Returns: 2
Both carols need to be sung.
1)
    
{"YN","YY","YN"}
Returns: 1
Everybody knows the first carol, so singing just that one is enough.
2)
    
{"YNN","YNY","YNY","NYY","NYY","NYN"}
Returns: 2
Singing the best known carol is not always the optimal strategy. Here, the optimal way is to pick the first two carols even though four people know the third one.
3)
    
{"YNNYYY","YYNYYY","YNNYYN","NYYNNN","YYYNNN","YYYNNY","NYYYYY","NYNYYY","NNNNYY",
 "YYYYYY","YNNNNN","YYYYNY","YYNNNN","NNYYYN","NNNNYY","YYYNNN","NYNNYN","YNNYYN",
 "YYNNNY","NYYNNY","NNYYYN","YNYYYN","NNNYNY","YYYYNN","YYNYNN","NYYNYY","YYNYYN"}
Returns: 4

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10011&pm=7280

Writer:

slex

Testers:

PabloGilberto , brett1479 , Olexiy , marian

Problem categories:

Brute Force, Graph Theory