Colorful balls
Practice
4 (185 votes)
Combinatorics
Dynamic programming
Approved
Easy Medium
Problem
80% Success 2651 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Today Oz is playing with colorful balls. He has A red balls, B blue balls, C green balls and D yellow balls. Using the balls, he wants to make a colorful straight line such that no two balls of same type are adjacent to each other. He also knows that their are many ways to make colorful straight line keeping the condition so first he wants to know how many ways are their to make colorful straight line. Help Oz with the answer.

Note:
Each ball of a given type is identical to others of the same type, thus swapping the positions of two of the same type of balls does not make a new arrangement.

Input:
First and the only line of the input contains four single space separated integers i.e \(A, B, C\) and D as described in the problem statement.

Output:
Output the number of ways to make a colorful straight line.

Constraints:

  • \(A , B, C and D \le 10\)

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
Points:30
58 votes
Tags:
AlgorithmsApprovedEasyGraphsOpen
Points:30
2 votes
Tags:
Ad-HocReadyAlgorithmsApprovedEasy-Medium
Points:30
207 votes
Tags:
ApprovedMathMediumReady