Cow Frisbee Team
InterviewTime limit1sMemory limit128 MB
Count the nonempty subsets of N cows whose rating sum is divisible by F, modulo 100000000.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
After Farmer Don took up Frisbee, Farmer John (FJ) wanted to join in the fun. He wants to form a Frisbee team from his cows (), conveniently numbered . Each cow has a rating () denoting her skill at playing Frisbee. FJ can form a team by choosing one or more of his cows.
However, because FJ is very selective when forming Frisbee teams, he adds one more constraint. His favorite number is (), and he will only accept a team if the sum of the ratings of the cows on it is exactly divisible by .
Help FJ find how many different teams he can choose. Two cows are always distinct, so teams made of different cows count separately even when their ratings match. Because this number can be very large, output the answer modulo .
Input
- Line : Two space-separated integers, and .
- Lines : Line contains a single integer, .
Output
- Line : A single integer, the number of teams FJ can choose, modulo .
Hint
In the example above, FJ can pair the with either of the two 's (), or he can use both 's together with the (). Because there are two cows rated , the combination counts as two distinct teams.