#P4370. [Code+#4] 组合数问题2

[Code+#4] 组合数问题2

Description

It is well known that Xiaocong is skilled at calculation, especially at computing binomial coefficients. Given two numbers nn and kk, he wants you to find kk distinct binomial coefficients such that their sum is maximized. By distinct binomial coefficients, for Ca1b1C_{a_1}^{b_1} and Ca2b2C_{a_2}^{b_2}, if a1a2a_1\neq a_2 or b1b2b_1\neq b_2, we consider them different. Now, please find such kk distinct binomial coefficients so that for any one of them CabC_a^b we have 0ban0\leq b\leq a\leq n. What is the maximum possible sum of these kk binomial coefficients?

Input Format

Read from standard input.

The first line contains two integers n,kn,k.

Output Format

Write to standard output.

One line with a single integer, representing the sum of the kk binomial coefficients modulo 109+710^9+7; it is guaranteed that there are at least kk numbers to choose from.

2 3
4

Hint

For 20% of the testdata, n10n\leq 10.

For 40% of the testdata, n500n\leq 500.

For another 20% of the testdata, k=1k=1.

For 100% of the testdata, 1n106,1k105.1\leq n\leq 10^6,1\leq k\leq 10^5.

Credit: https://www.luogu.org/discuss/show/38908

Translated by ChatGPT 5