编程介的小学生 2017-09-11 22:32 采纳率: 20.5%
浏览 759
已采纳

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条回答 默认 最新

  • threenewbee 2017-09-27 14:32
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办