和为 19 的数位
Digit Sum of 19
题目详情
100 万以下,各位数字之和为 19 的正整数有多少个?
How many positive integers are there under 1 million whose digits sum to 19?
解析
这是一个经典的计数问题,需要创造性地使用星形和条形计数技术。让我们首先概括一下所有小于 100 万的正整数的表达方式: 其中x是小于100万的正整数,每个是整数的位数。但请注意,每个 也受到约束: 因为每个 都是一个数字,并且数字必须在 0 到 9 之间。第三个也是最后一个约束是: 这是问题的关键,要求各位数字之和必须等于 19。
现在让我们来看看星条定理的应用。根据第三个约束,我们知道 6 位数字之和等于 19。这相当于将可用的 19 个“1”划分为 6 个不同的“bins”。每个 bin 对应一个特定的 。我们可以用 5 个不同的条形来执行这样的分区(因为 5 个条形创建 6 个分区空间)。因此,我们可以选择 使得总和等于 19 的方法数为: ,请注意,在这个特定分区中,我们允许每个 取 0 到 19 之间的任何值,而上面的约束编号 2 表示每个 只能取 0 到 9 之间的值(包含 0 和 9)。因此,我们必须使用 来计算无效分区的方式。这对应于 等于 10 或更大(最多 19)的计数。我们可以使用星形和条形的另一种实现来计算每个 的无效分区数。
将无效值 10 分配给单个 ,然后我们计算出分配剩余 9 个的路数。这将导致每个 的 无效。然后,我们将该值乘以 6(对于每个 ),并从上面的总分区计数中减去,得到最终值:
Original Explanation
This is a classic counting problem which requires the creative use of the stars and bars counting technique. Let's first begin by generalizing the ways that we can express all positive integers less than 1 million: where x is the positive integer less than 1 million, and each is the digit of integer . Notice, however, that each is also subject to the constraint: because each is a digit, and digits must be between 0 and 9. The third and last constraint would be that: This is the crux of the problem, and states that the sum of the digits must equal 19.
Let's now get into the application of the stars and bars theorem. By our third constraint, we know that the sum of 6 digits is equal to 19. This is equivalent to partitioning our available 19 'ones' into 6 different 'bins'. Each bin corresponds to a particular . We can execute such a partition with 5 different bars (since 5 bars create 6 partitioned spaces). As a result, the number of ways we can select such that the sum is equal to 19 is: , note that in this particular partition, we are allowing each to take on any value between 0 and 19, when constraint number 2 from above says that each can only take on values between 0 and 9, inclusive. As a result, we must out the ways in which we counted that were invalid partitions. This would correspond to counts where was equal to 10 or greater (up to 19). We can count the number of invalid partitions for each using another implementation of stars and bars.
Assigning an invalid value of 10 to a single , we then count out the number of ways to assign the remaining 9. This would result in invalid ways for each . We then multiply this value by 6 (for each ), and subtract from the total partition count from above, giving us a final value: