Buying Flowers
Time limit2sMemory limit512 MB
Count integer sequences x_i with 0 <= x_i <= f_i summing to S, where N <= 20 and S up to 1e14.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math, Bit manipulation
- Solved
- No attempts yet
Problem
Sanggeun wants to buy exactly flowers for his girlfriend.
There are flower shops in his neighborhood, and shop sells at most flowers. All flowers sold by one shop have the same color, and flowers of the same color cannot be told apart. No two shops sell the same color.
So a way of buying is decided by how many flowers he takes from each shop. Count the integer sequences with and .
Write a program that counts the ways to buy exactly flowers.
Input
The first line contains and . (, )
The second line contains separated by spaces. ()
Output
Print on the first line the number of ways to buy exactly flowers, modulo .