Buying Stamps
InterviewTime limit1sMemory limit1024 MB
Count the ways to buy stamps worth exactly K won from N kinds of 1-won and M kinds of 2-won stamps, modulo a prime P.
- Level
Easy3 of 10
- Topics
- Dynamic programming
- Solved
- No attempts yet
Problem
The post office sells stamps. There are kinds of stamps priced at 1 won and kinds priced at 2 won.
Write a program that counts the ways to buy stamps worth exactly won.
You may buy several stamps of the same kind. The post office has an unlimited number of each stamp. You must use exactly won.
Input
The first line contains , , , and . (, , , is prime.)
Output
Print the number of ways to buy stamps, modulo , on the first line.