Binomial Sum of Products
Practice
3.2 (15 votes)
Dynamic programming
Easy
Pascal's rule
Pascal's rule
Two dimensional
Problem
20% Success 6135 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
A function \(f(x,y)\) is defined as
\(f(x,y) = \binom{x}{y}\) if \(x \geq y\) else x x y
where \(\binom{x}{y} = \frac{x!}{y!(x-y)!}\)
There will be total q queries and each query will have four integers i.e. a, b, c and d. You need to compute the value of
\(\sum_{i = a}^b \prod_{j=c}^d\) \(f(i,j)\) for every query.
As the output number can be very large. So, you need to print answer modulo \(10^9+7\)
Note: \(0!=1\)
Input Format
- First line will have a single integer denoting the value of q.
- Each line in next q lines will have four space separated integers denoting the value of a,b,c and d.
Output Format
- Output q lines, where \(i^{th}\) line denoting the answer represents the answer of the \(i^{th}\) query modulo \(10^9+7\).
Constraints
- \(1\leq q \leq 1000\)
- \(0 \leq a \leq b \leq 1000\)
- \(0 \leq c \leq d \leq 1000\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
19 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingEasyOpen
Points:20
6 votes
Tags:
AlgorithmsDynamic Programming2D dynamic programming
Points:20
10 votes
Tags:
AlgorithmsDynamic ProgrammingEasyTwo dimensional
Editorial
Login to unlock the editorial