COCI '20 Contest 6 #3 Anagramistica

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem types

Biljana loves making crosswords. Her favourite type is the so called anagram crossword, where each clue is an anagram of the required solution.

She has a set of n words that she thinks would be good candidates for her next puzzle. We say that two words are similar if one can be obtained from the other by rearranging the letters (i.e., they are anagrams). She wants to select a subset of her words, such that there are exactly k pairs of similar words in that subset. Help Biljana determine the number of such subsets.

Input Specification

The first line contains integers n (1 \le n \le 2\,000) and k (0 \le k \le 2\,000), the number of words and the required number of similar pairs.

Each of the following n lines contains a word consisting of at most 10 lowercase letters. All words will be distinct.

Output Specification

Output the number of described subsets modulo 10^9 + 7.

Constraints

SubtaskPointsConstraints
1101 \le n \le 15
2300 \le k \le 3
370No additional constraints.

Sample Input 1

3 1
ovo
ono
voo

Sample Output 1

2

Explanation for Sample Output 1

Subsets with exactly one similar pair are {ovo, ono, voo} and {ovo, voo}.

Sample Input 2

5 2
trava
vatra
vrata
leo
ole

Sample Output 2

3

Sample Input 3

6 3
mali
lima
imal
je
sve
ej

Sample Output 3

6

Comments

There are no comments at the moment.