QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 2048 MB 満点: 100

#11352. 麻将

統計

麻将起源于中国,并已风靡全球。你不需要有任何麻将经验即可解决此问题,我们将使用不同的规则。

在我们这个版本的麻将中,玩家拥有一套 $4K$ 张牌。每张牌上都写有一个整数等级,从 $1$ 到 $K$ 的每个等级都有四张完全相同的牌。例如,当 $K=5$ 时,这套牌为:$1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5$。

玩家的目标是从这套牌中选出 $M$ 张牌组成一个“和牌”。一个和牌由若干个(可能为零)顺子或刻子(统称为“面子”)加上恰好一个对子组成。对子必须由两张相同等级的牌组成。面子可以是三张相同等级的牌(例如 “2 2 2”),也可以是三张连续等级的牌(例如 “3 4 5”)。等级不会循环——例如,“4 5 1” 不是一个有效的面子。

给定 $K$ 和 $M$,有多少种不同的和牌?如果两手牌使用的牌集合相同,则认为它们是相同的,无论这些牌是如何组合成面子和对子的。例如,对于 $K=4, M=8$,以下两手牌被视为相同: “1 2 3, 1 2 3, 4 4” “1 1, 2 3 4, 2 3 4”

输入格式

第一行输入包含测试用例的数量 $T(1 \le T \le 100)$。接下来有 $T$ 行。每行包含两个空格分隔的整数 $K(1 \le K \le 200)$ 和 $M(2 \le M \le \min(200, 4K)$ 且 $M \equiv 2 \pmod 3)$。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是和牌的数量,对 $1000000007 (10^9 + 7)$ 取模。

样例

样例输入 1

4
1 2
3 5
4 5
9 14

样例输出 1

Case #1: 1
Case #2: 9
Case #3: 20
Case #4: 13259

说明

在 Case #1 中,只有四张牌 —— $1, 1, 1, 1$,和牌必须仅由一个对子组成(没有面子)。只有一种可能性 —— “1 1”。(注意,所有的 ‘1’ 都是可互换的,选哪两张并不重要。)

在 Case #2 中,有十二张牌 —— $1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3$,和牌必须由一个面子和一个对子组成。九种可能的和牌为:

$1\ 1\ 1, 2\ 2$ $1\ 1\ 1, 3\ 3$ $2\ 2\ 2, 1\ 1$ $2\ 2\ 2, 3\ 3$ $3\ 3\ 3, 1\ 1$ $3\ 3\ 3, 2\ 2$ $1\ 2\ 3, 1\ 1$ $1\ 2\ 3, 2\ 2$ $1\ 2\ 3, 3\ 3$

注意,“3 3, 1 1 1” 不会被视为与 “1 1 1, 3 3” 不同的和牌 —— 只有牌的集合重要,而不是它们如何排列。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.