当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5548:Mahjong

题目描述
The game of Mahjong originated in China and has become popular around the world. You do not need to have prior experience with Mahjong to solve this problem, and we will use different rules.

In our version of Mahjong, the player is given a set of $4K$0 tiles. Each tile has an integer rank written on it, and there are four identical copies of each rank from 1 to $K$. For example, for $K=5$, the set of tiles would be: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5.

The player's goal is to select $M$ tiles from this set to form a winning hand. A winning hand consists of some number (possibly zero) of triples plus exactly one pair. A pair must consist of two tiles of the same rank. A triple can be either three tiles of the same rank (e.g., "2 2 2"), or three tiles with consecutive ranks (e.g., "3 4 5"). The ranks do not wrap around -- for example, "4 5 1" is not a valid triple.

Given $K$ and $M$, how many different winning hands are there? Two winning hands are considered the same if they use the same set of tiles, regardless of how those tiles are grouped to make triples and the pair. For instance, for $K=4$, $M=8$, the following two hands are considered the same:

"1 2 3, 1 2 3, 4 4"

"1 1, 2 3 4, 2 3 4"
输入解释
The first line of the input gives the number of test cases, $T(1≤T≤100)$. $T$ lines follow. Each line contains two space-separated integers, $K(1≤K≤200)$ and $M(2≤M≤min(200,4K)$ and $M≡2(mod3))$.
输出解释
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the number of winning hands, modulo $1000000007 (10^{9}+7)$.
输入样例
4
1 2
3 5
4 5
9 14
输出样例
Case #1: 1
Case #2: 9
Case #3: 20
Case #4: 13259
提示
In Case #1, there are only four tiles -- 1, 1, 1, 1 -- and the winning hand must consist of just a pair (with no triples). There is only one possibility -- "1 1". 
(Note that all the "1"s are interchangeable and it doesn't matter which two you pick.)

In Case #2, there are twelve tiles -- 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3 -- and the winning hand must consist of one triple and one pair. The nine possible hands are:

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

Note that "3 3, 1 1 1" would not be considered a different hand from "1 1 1, 3 3" -- only the set of tiles matters, not how they are arranged.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5548

最后修改于 2020-10-25T23:23:40+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 234567/234567K(Java/Others)