编程介的小学生 2017-09-24 12:07 采纳率: 20.5%
浏览 881
已采纳

Mahjong

Problem Description
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 4K0 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"

Input
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)).

Output
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(109+7).

Sample Input
4
1 2
3 5
4 5
9 14

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

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)