编程介的小学生 2017-05-05 12:53 采纳率: 20.5%
浏览 752
已采纳

Challenge 3D Tetris

Tetris is one of the few games that achieve ultimate popularity. It is remarkably simple, yet remarkably difficult. It's been ported to every computer and game console known to man, and has sold millions of copies across the land.
Today we are talking about a 3D Tetris game. The game goes on pretty much the same with conventional Tetris game, but you have more freedom with the pieces in that you can rotate in x-y plane, y-z plane or z-x plane. Flipping is also allowed. All the pieces descend along the z-axis, until any block of the descending piece encounters another block or the bottom of the space. A fully filled x-y plane will be removed and some points will be granted.

The pieces are constructed with cubic blocks of the same size. Two blocks are connected if they share a same face. A valid piece should have all the blocks in one component. Since we are free to rotate and flip the pieces, some of them are in fact equivalent to each other. Observing such rules, we can calculate the number of distinct valid pieces of n blocks. For instance, we have two distinct pieces constructed with three blocks, and seven distinct pieces constructed with four blocks.

Some times in order to make some extra fun, the game can generate a random configuration at start. Some layers of blocks will appear on the bottom of the space. As the game goes on, at the moment you reduce all the blocks (both the originally generated ones and the ones later filled into the space), you win a special bonus.

As the designer of such rules, I am well aware of the fact that some random generated configuration will never lead to the special bonus. That is why I need a program to verify it. And after some tedious case study, I believe the possibility is only related to the number of blocks generated, the area of the x-y plane and the piece types used. Now here goes your job.

Input

The first line of the input is an integer N (N <= 10000), which is the total number of test cases.

Each test case occupies one line in the input. The first integer is the area of the x-y place, the next integer is the number of generated blocks. The third integer is n (n <= 10), which is the number of piece types. We do allow mixed piece types in one game. The last n integers are the number of blocks in each type. These n integers are distinct.

During the game, the pieces are generated randomly, but all valid according to the rules above.

All the numbers in the input will fit into a 64-bit unsigned integer, unless declared otherwise.

Output

Print one line for each test case, either the word YES when a special bonus is achievable, or NO otherwise.

Sample Input

2
4 2 1 2
4 1 2 1 2

Sample Output

YES
YES

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据