TopCoder problem "TheQuestionsAndAnswersDivOne" used in SRM 460 (Division I Level One)



Problem Statement

    

John and Brus have become very famous people all over the world, especially in Bolivia. A man in Bolivia decided to write a story about them. To make the story more truthful, he set up an interview with John. He prepared a list of distinct simple "Yes" or "No" questions and he enlisted the help of two friends to transcribe the interview. Each time he asked a question, one friend wrote down the question while the other friend wrote down the answer. He was very nervous when conducting the interview, so he might have asked some of the questions multiple times. However, John's answers always remained the same for the same questions.

Unfortunately, the friend who was writing down the questions lost his list. In a desperate attempt to remember the order in which he asked the questions, the Bolivian has decided to write down all the possible ways that he might have asked them. He knows for sure that he asked every question from his list at least once. You are given an int questions, which is the number of questions that were in his list, and a String[] answers, the i-th element of which is the answer to the i-th question he asked. Return the total number of ways in which he might have asked the questions.

 

Definition

    
Class:TheQuestionsAndAnswersDivOne
Method:find
Parameters:int, String[]
Returns:int
Method signature:int find(int questions, String[] answers)
(be sure your method is public)
    
 

Constraints

-questions will be between 2 and 9, inclusive.
-answers will contain between questions and 9 elements, inclusive.
-Each element of answers will be either "Yes" or "No".
 

Examples

0)
    
2
{"No", "Yes"}
Returns: 2
The two possible ways are: the first question followed by the second question, or vice versa.
1)
    
2
{"No", "No", "No"}
Returns: 6
2)
    
3
{"Yes", "No", "No", "Yes"}
Returns: 12
3)
    
3
{"Yes", "Yes", "Yes", "No"}
Returns: 18

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14146&pm=10768

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , connect4 , ivan_metelsky

Problem categories:

Dynamic Programming