编程介的小学生 2017-03-24 13:41 采纳率: 20.5%
浏览 1223
已采纳

Toy Bricks

Tom has a lot of toy bricks. All of them are 1*1*L cuboids. This day, Tom gets a picture on which is a beautiful house. "Great, I'll build this house with my toy bricks!" Tom shouts excitedly. However, he does not know it is possible to build this house. So he asks for your help.

The house model designed by Tom can be viewed as a N*N*N cube losing some of its blocks. However, his toy bricks are limited and his design may not be stable. In other words, the house may not be able to stand on ground stably. It is your job to help him to find out these defects.

You may assume that all toy bricks can glue to each other tightly.

Input

The input consists of multiple test cases. Each test case starts with a positive integer N(<=5). Following is the description of the house model. The description consists of N 0-1 matrixes, which represent N layers of the cube from bottom to top respectively. Each matrix is N*N. If an element is 1, then there is a block, otherwise there is not. After the house model, there is a single line containing several positive integers representing Tom's toy bricks. Each integer is the length of corresponding toy brick.

Output

For each test case, output "Yes" if the house can be built, "No" otherwise.

Sample Input

3
101
000
101
101
000
101
111
111
111
1 1 1 2 2 2 3 3 3

3
100
000
000
110
010
000
100
010
000
1 1 1 1 /* not stable /
2
11
11
10
01
1 1 1 /
not enough bricks */

Sample Output

Yes
No
No

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-04-02 15:37
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败