编程介的小学生 2017-08-15 08:26 采纳率: 20.5%
浏览 732
已采纳

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

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!