#P9131. [USACO23FEB] Problem Setting P

[USACO23FEB] Problem Setting P

题目描述

Note: The memory limit for this problem is 512MB, twice the default.

Farmer John created N(1N105)N(1 \le N \le 10^5) problems. He then recruited M(1M20)M (1 \le M \le 20) test-solvers, each of which rated every problem as "easy" or "hard."

His goal is now to create a problemset arranged in increasing order of difficulty, consisting of some subset of his NN problems arranged in some order. There must exist no pair of problems such that some test-solver thinks the problem later in the order is easy but the problem earlier in the order is hard.

Count the number of distinct nonempty problemsets he can form, modulo 109+710^9+7.

输入格式

The first line contains NN and MM.

The next MM lines each contain a string of length NN. The ii-th character of this string is E if the test-solver thinks the ith problem is easy, or H otherwise.

输出格式

The number of distinct problemsets FJ can form, modulo 109+710^9+7.

题目大意

Farmer John 出了 nn 道题,聘了 mm 个验题人来品鉴难度。

难度只有简单(E)和困难(H)两种。

Farmer John 将从中选出若干道(至少一道),并以一定顺序排列,使得前一道题目中任意一个觉得此题困难的验题人也觉得后面一道题目困难。

回答有多少种选出来并排列的方案,对 109+710^9+7 取模。

1n1051\le n\le10^51m201\le m\le20

3 1
EHE
9
10 6
EHEEEHHEEH
EHHHEEHHHE
EHEHEHEEHH
HEHEEEHEEE
HHEEHEEEHE
EHHEEEEEHE
33

提示

Explanation for Sample 1

The nine possible problemsets are as follows:

[1][1]
[1,2][1,2]
[1,3][1,3]
[1,3,2][1,3,2]
[2][2]
[3][3]
[3,1][3,1]
[3,2][3,2]
[3,1,2][3,1,2]

Note that the order of the problems within the problemset matters.

SCORING

  • Inputs 343-4: M=1M=1
  • Inputs 5145-14: M16M \le 16
  • Inputs 152215-22: No additional constraints.