编程介的小学生 2017-08-19 08:05 采纳率: 20.5%
浏览 859
已采纳

Tiling Dominoes

描述
Is it possible to tile a chessboard of size N*M with dominoes of size 2*1, satisfying that each square is covered exactly once?

Foreseeable is such a smart guy to solve this problem. But what he really wants is a compact solution. A solution is called compact if and only if after Foreseeable tiles the chessboard like that, he cannot divide the chessboard into two rectangles without cutting off any piece of domino.

Can you find a compact solution for him?

输入
The first line contains an integer T (1 <= T <= 200), indicating the number of test cases.

For each test case:

One line contains two integers N and M (1 <= N,M <= 100), indicating the size of the chessboard.
输出
For each test case:

If there is no compact solution, output "impossible" on a single line;

If there are several compact solutions, output any one of them. Output N lines, each line contains a string of M upper case letters ("A" to "Z"), indicating the way to tile the chessboard with dominoes. Each domino is represented by two adjacent (sharing a common edge) squares with the same letter. You can mark each domino with any upper case letter, however, any two adjacent (sharing at least one common edge) dominoes should be marked with different letters.
样例输入
4
1 2
3 4
5 6
7 7
样例输出
AA
impossible
ABBABB
ACCADC
CDBBDC
CDACCA
BBABBA
impossible

  • 写回答

1条回答 默认 最新

  • devmiao 2017-08-29 16:40
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集