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)×33)ord(letter))%MOD

The function is defined for words that consist of only lowercase letters of the English alphabet. stands for the bitwise XOR operator (e.g. 01101010=1100), ord(letter) stands for the ordinal number of the letter in the alphabet (ord(a)=1, ord(z)=26) and A%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 2M.

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 (1N10,0K<2M,6M25).

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

Copy
1 0 10

Sample Output 1

Copy
0

Explanation for Sample Output 1

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

Sample Input 2

Copy
1 2 10

Sample Output 2

Copy
1

Explanation for Sample Output 2

It is the word b.

Sample Input 3

Copy
3 16 10

Sample Output 3

Copy
4

Explanation for Sample Output 3

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


Comments

There are no comments at the moment.