编程介的小学生 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 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法