title: Facebook Programming Challenge
body: <p>Mastermind is a game of two players. In the beginning, first player decides a secret key, which is a sequence <code>(s1,s2,...sk)</code> where <code>0 &lt; si &lt;= n</code>, Then second player makes guesses in rounds, where each guess is of form <code>(g1,g2, ...gk)</code>, and after each guess first player calculates the score for the guess. Score for a guess is equal to number of i's for which we have <code>gi = si</code>.</p>
  
  <p>For example if the secret key is <code>(4,2,5,3,1)</code> and the guess is <code>(1,2,3,7,1)</code>,then the score is 2, because
  <code>g2 = s2</code> and <code>g5 = s5</code>. </p>
  
  <p>Given a sequence of guesses, and scores for each guess, your program must decide if there exists at least one secret key that generates those exact scores.</p>
  
  <p>Input</p>
  
  <p>First line of input contains a single integer <em>C</em> <code>(1 &lt;=C &lt;= 100)</code>. C test-cases follow. First line of each test-case contains three integers <em>n</em>, <em>k</em> and <em>q</em>. <code>(1 &lt;=n,k &lt;=11, 1&lt;=q&lt;=8)</code>. Next <em>q</em> lines contain the guesses.</p>
  
  <p>Each guess consists of <em>k</em> integers <code>gi,1, gi,2,....gi,k</code> separated by a single space, followed by the score for the guess <em>bi</em> <code>(1 &lt;= gi,j &lt;=n for all 1 &lt;=i &lt;=q, 1 &lt;=j &lt;=k; and 0 &lt;= bi &lt;=k )</code></p>
  
  <p>Output</p>
  
  <p>For each test-case, output "Yes" (without quotes), if there exists at least a secret key which generates those exact scores, otherwise output "No".</p>
  
  <p>Sample Input</p>
  
  <pre><code>2
  4 4 2
  2 1 2 2 0
  2 2 1 1 1
  4 4 2
  1 2 3 4 4
  4 3 2 1 1
  </code></pre>
  
  <p>Sample Output</p>
  
  <pre><code>Yes
  No
  </code></pre>
  
  <p>I am not able to think anything else except brute force i.e. by generating all the possible keys and checking the respective score for all the guesses 
  The complexity is a very high will do approx (11^11)*8 operations </p>
  
  <p>Plz suggest something how to do this in time?</p>
  
  <p>time limit: 3 sec</p>