5916. A. 骰子游戏
时间限制:1000 MS 内存限制:256 MB
题目描述
## 题目描述 You are attempting to create a new game that is played by rolling several dice. In order to determine scoring, you need to first know how many different formations can be rolled with those dice. We define a formation as the collection of values that are shown on the dice, without regard to order. Thus, {1, 1, 2}, {1, 2, 1}, and {2, 1, 1} are all the same formation, whereas {1, 1, 2}, {1, 2, 2} and {1, 1, 3} are all different formations. Note that even though two dice may have a different number of sides, for the purpose of counting formations, only the number shown on them matters. You are given a int[] sides, where the i-th element is the number of sides on the i-th die. The sides of an n-sided die contain all numbers between 1 and n, inclusive. Return the number of different formations that can be made from those dice. 你正在尝试设计一款新游戏,玩法是投掷若干个骰子。要确定得分规则,首先需要知道用这些骰子能掷出多少种不同的“组合形态”。 我们将“组合形态”定义为骰子朝上的数字集合,且**不考虑数字的先后顺序**。因此,{1, 1, 2}、{1, 2, 1}和{2, 1, 1}属于同一种组合形态;而{1, 1, 2}、{1, 2, 2}和{1, 1, 3}则是三种不同的组合形态。需要注意的是,即使两个骰子的面数不同,在统计组合形态时,也只关注它们掷出的数字本身。 给定一个整数数组sides,其中第i个元素表示第i个骰子的面数。n面骰子的所有面分别标有1到n的数字(包含1和n)。 请返回用这些骰子能掷出的不同组合形态的总数。 ## 输入格式 Length of sides int[] sides ## 输出格式 long ### 样例 ## 输入 ```in1 1 4 ``` ## 输出 ```out1 4 ``` ## 说明 A single die with four sides can have four formations. ```in2 2 2 2 ``` ```out2 3 ``` ## 说明 This is essentially the equivalent of flipping two coins. We can get Heads/Heads, Heads/Tails, or Tails/Tails. ```in3 2 4 4 ``` ```out3 10 ``` ## 说明 Here, there are 10 formations we can make: {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}, {2, 3}, {2, 4}, {3, 3}, {3, 4}, {4, 4}. ```in4 2 3 4 ``` ```out4 9 ``` ## 说明 Now it is impossible to get {4, 4} because the first die has only 3 sides. ```in5 3 4 5 6 ``` ```out5 48 ``` ## 数据范围 - sides will contain between 1 and 32 elements, inclusive. - Each element of sides will be between 1 and 32, inclusive.