F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Guess the Pattern

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 214    Accepted Submission(s): 27
Special Judge


Problem Description
Given a 01 string, you can group consecutive 1¡¯s into blocks and write down their lengths. This is called the ¡®block length sequence (BLS)¡¯ for that string. For example, the BLS for 011100110100011 is 3, 2, 1, 2.

Similarly, given a 01 matrix, you can write down the BLS for each row and each column. Given these BLS¡¯s, your task is to restore the 01 matrix.

Rows are read from left to right, while columns are read from top to bottom. Each test case is guaranteed to be solvable, and you¡¯re free to output any (but only one!) solution you like.
 

Input
The input contains at most 10 test cases. Each test case begins with two integers n and m (1 <= n, m <= 15), the number of rows and the number of columns. The next n lines contain the BLS¡¯s for each row, from top to bottom, and the next m lines contains the BLS¡¯s for each column, from left to right. Each BLS ends with zero. The input ends with n = m = 0.
 

Output
For each case, print exactly one feasible solution you find. Each row of the matrix should occupy exactly one line. There shouldn¡¯t be any spaces within the matrix, nor there can be any empty lines between rows, but do print an empty after each test case.
 

Sample Input
4 4 2 1 0 3 0 3 0 1 1 0 4 0 3 0 3 0 1 0 0 0
 

Sample Output
**.* ***. ***. *.*.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 04:47:16, Gzip enabled