返回题库

和为 19 的数位

Digit Sum of 19

专题
Discrete Math / 离散数学
难度
L7

题目详情

100 万以下,各位数字之和为 19 的正整数有多少个?

How many positive integers are there under 1 million whose digits sum to 19?

解析

这是一个经典的计数问题,需要创造性地使用星形和条形计数技术。让我们首先概括一下所有小于 100 万的正整数的表达方式: x=x1,x2,x3,x4,x5,x6x = x_1, x_2, x_3, x_4, x_5, x_6 其中x是小于100万的正整数,每个xix_i是整数xxithith位数。但请注意,每个 xix_i 也受到约束: 0xi90 \leq x_i \leq 9 因为每个 xix_i 都是一个数字,并且数字必须在 0 到 9 之间。第三个也是最后一个约束是: x1+x2+x3+x4+x5+x6=19x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 19 这是问题的关键,要求各位数字之和必须等于 19。

现在让我们来看看星条定理的应用。根据第三个约束,我们知道 6 位数字之和等于 19。这相当于将可用的 19 个“1”划分为 6 个不同的“bins”。每个 bin 对应一个特定的 xix_i。我们可以用 5 个不同的条形来执行这样的分区(因为 5 个条形创建 6 个分区空间)。因此,我们可以选择 x1...x6x_1 ... x_6 使得总和等于 19 的方法数为: (19+55)=(245){{19+5} \choose 5} = {{24} \choose5} HoweverHowever,请注意,在这个特定分区中,我们允许每个 xix_i 取 0 到 19 之间的任何值,而上面的约束编号 2 表示每个 xix_i 只能取 0 到 9 之间的值(包含 0 和 9)。因此,我们必须使用 subtractsubtract 来计算无效分区的方式。这对应于 xix_i 等于 10 或更大(最多 19)的计数。我们可以使用星形和条形的另一种实现来计算每个 xix_i 的无效分区数。

将无效值 10 分配给单个 xix_i,然后我们计算出分配剩余 9 个的路数。这将导致每个 xix_i(9+55)=(145){{9+5} \choose5} = {{14} \choose5} 无效。然后,我们将该值乘以 6(对于每个 xix_i),并从上面的总分区计数中减去,得到最终值: (245)6(145)\boxed{ {{24} \choose5} - 6*{{14} \choose5} }


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: x=x1,x2,x3,x4,x5,x6x = x_1, x_2, x_3, x_4, x_5, x_6 where x is the positive integer less than 1 million, and each xix_i is the ithith digit of integer xx. Notice, however, that each xix_i is also subject to the constraint: 0xi90 \leq x_i \leq 9 because each xix_i is a digit, and digits must be between 0 and 9. The third and last constraint would be that: x1+x2+x3+x4+x5+x6=19x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 19 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 xix_i. 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 x1...x6x_1 ... x_6 such that the sum is equal to 19 is: (19+55)=(245){{19+5} \choose 5} = {{24} \choose5} HoweverHowever, note that in this particular partition, we are allowing each xix_i to take on any value between 0 and 19, when constraint number 2 from above says that each xix_i can only take on values between 0 and 9, inclusive. As a result, we must subtractsubtract out the ways in which we counted that were invalid partitions. This would correspond to counts where xix_i was equal to 10 or greater (up to 19). We can count the number of invalid partitions for each xix_i using another implementation of stars and bars.

Assigning an invalid value of 10 to a single xix_i, we then count out the number of ways to assign the remaining 9. This would result in (9+55)=(145){{9+5} \choose5} = {{14} \choose5} invalid ways for each xix_i. We then multiply this value by 6 (for each xix_i), and subtract from the total partition count from above, giving us a final value: (245)6(145)\boxed{ {{24} \choose5} - 6*{{14} \choose5} }