Pekka's Amusement
InterviewTime limit1sMemory limit1024 MB
Count the arrangements of multiset cards numbered 1..N where every card numbered k+1 appears after at least one card numbered k. Total cards up to 100.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math, Implementation
- Solved
- No attempts yet
Problem
Recently Pekka found a new amusement. He took identical cards with the number 1 written on each, cards with the number 2, , cards with the number . He wants to know in how many ways all the cards can be arranged in a row so that in the resulting sequence, every card with the number is preceded by at least one card with the number , for . Help Pekka, please.
Input
The first line of the input contains the natural number . The second line contains space-separated natural numbers: . The sum of all does not exceed .
Output
Output the number of distinct card arrangements that satisfy the condition of the problem.
Hint
Possible arrangements in the example: 1 1 2 2, 1 2 1 2, 1 2 2 1. There are three arrangements in total.