問題一覧 > 通常問題

No.117 Number of Combinations

レベル : / AI推定難易度 : 875 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 254
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 184 / 自分の提出
問題文最終更新日: 2018-09-07 17:30:49
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 72 (順位表) の他の問題:

Problem Statement

Let $C(N,K)$ denote the number of ways to choose $K$ distinct integers from the $N$ integers between $1$ and $N$, inclusive.
Let $P(N,K)$ denote the number of ways to choose $K$ distinct integers from the $N$ integers between $1$ and $N$, inclusive, and arrange them in order.
Let $H(N,K)$ denote the number of ways to choose $K$ integers, with repetition allowed, from the $N$ integers between $1$ and $N$, inclusive.
(Concrete examples are given in the explanation of Sample 1; refer to it if necessary.)
You are given $T$ queries. Each query gives one of $C(N,K), P(N,K), H(N,K)$. Write a program that computes its value ${\rm mod}\ 10^9+7$.

Input

$T$
$S_1$
$S_2$
$\vdots$
$S_T$

$1 \leq T \leq 10^5$
$S_k$ has one of the forms $C(N,K), P(N,K), H(N,K)$, where $N,K$ satisfy $0 \leq N,K \leq 10^6$
The input does not contain any extra spaces or the like. See the samples for the detailed input format

Output

For each query, output its value ${\rm mod}\ 10^9+7$ on $1$ line.

Sample

Sample 1
Input
5
C(4,2)
C(5,1)
P(3,2)
P(10,10)
H(3,2)
Output
6
5
6
3628800
6

The numbers of combinations satisfying the conditions are as follows:
For the $1$st query, there are $6$ ways: $\{1,2\}, \{1,3\}, \{1,4\}, \{2,3\}, \{2,4\}, \{3,4\}$.
For the $2$nd query, there are $5$ ways: $\{1\}, \{2\}, \{3\}, \{4\}, \{5\}$.
For the $3$rd query, there are $6$ ways: $(1,2),(1,3),(2,1),(2,3),(3,1),(3,2)$.
For the $4$th query, the count equals the number of ways to rearrange the integers from $1$ to $10$, so there are $10!$ ways.
For the $5$th query, there are $6$ ways: $\{1,1\}, \{1,2\}, \{1,3\}, \{2,2\}, \{2,3\}, \{3,3\}$.

Sample 2
Input
5
C(1,1000000)
C(0,0)
P(1000000,1000000)
P(1,10)
H(1,1000)
Output
0
1
641102369
0
1

For the $1$st query, it is impossible to choose $10^6$ distinct integers, so the answer is $0$.
For the $2$nd query, there is $1$ way to choose $0$ integers: choosing nothing.
For the $3$rd query, do not forget to output the answer ${\rm mod}\ 10^9+7$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。