C - Keys Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

あなたは NN 本の鍵 1,2,,N1,2,\dots,N を持っています。
このうち何本かの鍵は正しい鍵で、それ以外はダミーの鍵です。

また、鍵を何本でも挿し込める ドアX があり、この ドアX は正しい鍵を KK 本以上挿し込んだ時、またその時に限って開きます。

あなたはこれらの鍵に対して MM 回のテストを行いました。このうち ii 回目のテストの内容は次の通りです。

  • CiC_i 本の鍵 Ai,1,Ai,2,,Ai,CiA_{i,1},A_{i,2},\dots,A_{i,C_i} を ドアX に挿し込む。
  • テスト結果はひとつの英文字 RiR_i で表現される。
    • Ri=R_i = o のとき ii 回目のテストでドアが開いたことを表す。
    • Ri=R_i = x のとき ii 回目のテストでドアが開かなかったことを表す。

各鍵が正しいかダミーかの組み合わせは 2N2^N 通り考えられますが、このうちどのテスト結果にも矛盾しない組み合わせの個数を求めてください。
ただし、与えられるテスト結果が誤っており上記の条件を満たす組み合わせが存在しない場合もあります。その場合は 00 通りと解答してください。

制約

  • N,M,K,Ci,Ai,jN,M,K,C_i,A_{i,j} は整数
  • 1KN151 \le K \le N \le 15
  • 1M1001 \le M \le 100
  • 1CiN1 \le C_i \le N
  • 1Ai,jN1 \le A_{i,j} \le N
  • jkj \neq k ならば Ai,jAi,kA_{i,j} \neq A_{i,k}
  • RiR_io または x

入力

入力は以下の形式で標準入力から与えられる。

NN MM KK
C1C_1 A1,1A_{1,1} A1,2A_{1,2} \dots A1,C1A_{1,C_1} R1R_1
C2C_2 A2,1A_{2,1} A2,2A_{2,2} \dots A2,C2A_{2,C_2} R2R_2
\vdots
CMC_M AM,1A_{M,1} AM,2A_{M,2} \dots AM,CMA_{M,C_M} RMR_M

出力

答えを整数として出力せよ。


入力例 1Copy

Copy
3 2 2
3 1 2 3 o
2 2 3 x

出力例 1Copy

Copy
2

この入力では鍵が 33 本あり、テストは 22 回行われました。
また、 ドアX を開くのに必要な正しい鍵の本数は 22 本です。

  • 11 回目のテストでは鍵 1,2,31,2,3 を使い、その結果 ドアX は開きました。
  • 22 回目のテストでは鍵 2,32,3 を使い、その結果 ドアX は開きませんした。

各鍵が正しいかダミーかの組み合わせであって、どのテスト結果にも矛盾しないものは以下の 22 通りです。

  • 11 は本物、鍵 22 はダミー、鍵 33 は本物である。
  • 11 は本物、鍵 22 は本物、鍵 33 はダミーである。

入力例 2Copy

Copy
4 5 3
3 1 2 3 o
3 2 3 4 o
3 3 4 1 o
3 4 1 2 o
4 1 2 3 4 x

出力例 2Copy

Copy
0

問題文中でも述べた通り、答えが 00 通りである場合もあります。


入力例 3Copy

Copy
11 4 9
10 1 2 3 4 5 6 7 8 9 10 o
11 1 2 3 4 5 6 7 8 9 10 11 o
10 11 10 9 8 7 6 5 4 3 2 x
10 11 9 1 4 3 7 5 6 2 10 x

出力例 3Copy

Copy
8

Score : 300300 points

Problem Statement

You have NN keys numbered 1,2,,N1, 2, \dots, N.
Some of these are real keys, while the others are dummies.

There is a door, Door X, into which you can insert any number of keys. Door X will open if and only if at least KK real keys are inserted.

You have conducted MM tests on these keys. The ii-th test went as follows:

  • You inserted CiC_i keys Ai,1,Ai,2,,Ai,CiA_{i,1}, A_{i,2}, \dots, A_{i,C_i} into Door X.
  • The test result is represented by a single English letter RiR_i.
    • Ri=R_i = o means that Door X opened in the ii-th test.
    • Ri=R_i = x means that Door X did not open in the ii-th test.

There are 2N2^N possible combinations of which keys are real and which are dummies. Among these, find the number of combinations that do not contradict any of the test results.
It is possible that the given test results are incorrect and no combination satisfies the conditions. In such a case, report 00.

Constraints

  • NN, MM, KK, CiC_i, and Ai,jA_{i,j} are integers.
  • 1KN151 \le K \le N \le 15
  • 1M1001 \le M \le 100
  • 1CiN1 \le C_i \le N
  • 1Ai,jN1 \le A_{i,j} \le N
  • Ai,jAi,kA_{i,j} \neq A_{i,k} if jkj \neq k.
  • RiR_i is o or x.

Input

The input is given from Standard Input in the following format:

NN MM KK
C1C_1 A1,1A_{1,1} A1,2A_{1,2} \dots A1,C1A_{1,C_1} R1R_1
C2C_2 A2,1A_{2,1} A2,2A_{2,2} \dots A2,C2A_{2,C_2} R2R_2
\vdots
CMC_M AM,1A_{M,1} AM,2A_{M,2} \dots AM,CMA_{M,C_M} RMR_M

Output

Print the answer as an integer.


Sample Input 1Copy

Copy
3 2 2
3 1 2 3 o
2 2 3 x

Sample Output 1Copy

Copy
2

In this input, there are three keys and two tests were conducted.
Two correct keys are required to open Door X.

  • In the first test, keys 1,2,31, 2, 3 were used, and Door X opened.
  • In the second test, keys 2,32, 3 were used, and Door X did not open.

There are two combinations of which keys are real and which are dummies that do not contradict any of the test results:

  • Key 11 is real, key 22 is a dummy, and key 33 is real.
  • Key 11 is real, key 22 is real, and key 33 is a dummy.

Sample Input 2Copy

Copy
4 5 3
3 1 2 3 o
3 2 3 4 o
3 3 4 1 o
3 4 1 2 o
4 1 2 3 4 x

Sample Output 2Copy

Copy
0

As mentioned in the problem statement, the answer may be 00.


Sample Input 3Copy

Copy
11 4 9
10 1 2 3 4 5 6 7 8 9 10 o
11 1 2 3 4 5 6 7 8 9 10 11 o
10 11 10 9 8 7 6 5 4 3 2 x
10 11 9 1 4 3 7 5 6 2 10 x

Sample Output 3Copy

Copy
8


2025-04-24 (Thu)
05:23:32 +00:00