Hamming Ellipses
Time limit5sMemory limit512 MB
Count words of length n over a q-symbol alphabet whose Hamming distances to two given words sum to exactly D.
- Level
Medium5 of 10
- Topics
- Combinatorics, Math, String, Implementation
- Solved
- No attempts yet
Problem
In geometry an ellipse is defined by two focal points , and a length . The ellipse is the set of all points with .
The usual setting for an ellipse is the Euclidean plane with the Euclidean distance.
This problem uses a different kind of ellipse. The space here is the space of words of length over an alphabet of distinct symbols, written . For given and there are points, that is words, in .
The distance measure is the Hamming distance. The Hamming distance between two words is the number of positions where the symbols of and differ. For example, the Hamming distance between the words 01201 and 21210 is 3, because the words carry different symbols in three positions. The Hamming distance between any two words in is always an integer between 0 and , inclusive.
Inside the Hamming ellipse is the set of all points with . Given and , the two focal points and , and the distance , determine how many points lie on this Hamming ellipse.
Input
The first line contains three integers (), () and ().
The second and third lines give the two focal points and in that order. Each line is a string of length over the digits .
Output
Print one line with a single integer, the number of points on the ellipse. The input is chosen so that the answer is less than .