Connection Status:
Competition Arena > CarolsSinging
SRM 331 · 2006-12-21 · by slex · Brute Force, Graph Theory
Class Name: CarolsSinging
Return Type: int
Method Name: choose
Arg Types: (vector<string>)
Problem Statement

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.

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","NY","YN"}
Returns: 2
2)
{"YN","YY","YN"}
Returns: 1

Everybody knows the first carol, so singing just that one is enough.

3)
{"YN"}
Returns: 1
4)
{"Y"}
Returns: 1
5)
{"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.

Submissions are judged against all 59 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CarolsSinging with a public method int choose(vector<string> lyrics) · 59 test cases · 2 s / 256 MB per case

Submitting as anonymous