Optimal gems
Practice
3 (1 votes)
Open
Open
Dynamic programming
4d dynamic programming
Data structures
Medium
Algorithms
4 dimensional
Open
Approved
Problem
44% Success 184 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given four different types of gems that are denoted by \(G1\), \(G2\), \(G3\), and \(G4\). Their quantity is given by \( n1\), \(n2\), \(n3\), and \(n4\) respectively. You are required to arrange these gems in a straight line next to each other. However, in this arrangement, you want no two gems of the same type to be adjacent to each other.

Your task is to determine the number of distinct arrangements of the gems that exist. If yes, print the answer modulo \(10^9+7\)

Input format

The only line of the input contains four integers denoting the number of available gems of each type.

Output format

Print the required answer modulo \(10^9+7\).

Constraints

\( 0 \le n1, n2, n3, n4 \le 20 \)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
No similar problems found
Editorial

Login to unlock the editorial