COCI '13 Contest 6 #5 Hash

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

Little Mirko is studying the hash function which associates numerical values to words. The function is defined recursively in the following way:

  • f(empty word) = 0
  • f(word + letter) = ((f(word) \times 33) \oplus ord(letter)) \mathbin\% MOD

The function is defined for words that consist of only lowercase letters of the English alphabet. \oplus stands for the bitwise XOR operator (e.g. 0110 \oplus 1010 = 1100), ord(letter) stands for the ordinal number of the letter in the alphabet (ord(a) = 1, ord(z) = 26) and A \mathbin\% B stands for the remainder of the number A when performing integer division with the number B. MOD will be an integer of the form 2^M.

Some values of the hash function when M = 10:

  • f(a) = 1
  • f(aa) = 32
  • f(kit) = 438

Mirko wants to find out how many words of length N there are with the hash value K. Write a programme to help him calculate this number.

Input Specification

The first line of input contains three integers N, K and M (1 \le N \le 10, 0 \le K < 2^M, 6 \le M \le 25).

Output Specification

The first and only line of output must consist of the required number from the task.

Scoring

In test cases worth 30\% of total points, N will not exceed 5.

Additionally, in test cases worth 60\% of total points, M will not exceed 15.

Sample Input 1

1 0 10

Sample Output 1

0

Explanation for Sample Output 1

None of the characters in the alphabet has an ord value 0.

Sample Input 2

1 2 10

Sample Output 2

1

Explanation for Sample Output 2

It is the word b.

Sample Input 3

3 16 10

Sample Output 3

4

Explanation for Sample Output 3

Those are the words dxl, hph, lxd and xpx.


Comments

There are no comments at the moment.