- 如果我从集合 $\{1, 2, ..., m\}$ 中任意选出 $n$ 个不同的数字(不考虑顺序),比如选出了 $\{2, 5, 3\}$。
- 选出后,因为数字各不相同,必须把它们按从小到大排序,变成 $\{2, 3, 5\}$,这就唯一对应了题目中的一个合法序列。
- 反过来,题目中任何一个严格递增的序列,去掉角标后就是一个确定的子集。
因为“选数字”这个动作不考虑顺序,方案数就是组合数 $C_m^n$。
:::
所以从 $[1, n - 1]$ 中选出任意 $m - 1$ 个不重复元素按从大到小的顺序放入 $a_2, a_3, \dots a_m$ 即可。
即 $C_{n - 1}^{m - 1}$。
### AC_Code
```Cpp
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + 7;
int qmi(int a, int b, int p)
{
int res = 1 % p;
while (b)
{
if (b & 1)
res = (LL)res * a % p;
a = (LL)a * a % p;
b >>= 1;
}
return res;
}
int fact(int x)
{
int res = 1;
for (int i = 1; i <= x; ++ i )
res = (LL)res * i % MOD;
return res;
}
int infact(int x)
{
return qmi(fact(x), MOD - 2, MOD);
}
int C(int a, int b)
{
if (a < b)
return 0;
return (LL)fact(a) * infact(b) % MOD * infact(a - b) % MOD;
}
int main()
{
int a, b;
cin >> a >> b;
cout << C(b - 1, a - 1) << endl;
return 0;
}
```