Please read the new rule regarding the restriction on the use of AI tools. ×

abcd1204's blog

By abcd1204, 10 years ago, In English

Problem: A binary matrix is an m x n matrix consisting of only zeroes and ones. Now you are given m integers, ith integer indicating the summation of the values of cells in ith row. You are also given n integers, ith integer indicating the summation of the values of cells in jth column.

Your task is to generate the binary matrix. As there can be multiple solutions, we want the solution which is lexicographically smallest. To compare two solutions, we first find the cell (topmost, then leftmost) where the solutions differ; then the solution which contains 0 in that cell is lexicographically smaller. So,

001 001

010 < 100

100 010

Input.

Input starts with an integer T (≤ 125), denoting the number of test cases.

Each case starts with a line containing two integers: m and n (1 ≤ m, n ≤ 50). The next line contains m integers, separated by a single space, denoting the row sums. The next line contains n integers, separated by spaces, denoting the column sum. All the integers will be between 0 and 50 (inclusive).

Output.

For each case, print the case number first. Then if there is no solution, then print 'impossible' on the same line. Otherwise, from the next line, print m lines each having n characters denoting the binary matrix as stated above.

Sample Input

5

3 3

1 1 1

1 1 1

3 3

1 1 2

2 2 1

2 3

30 30

30 20 10

2 9

5 5

1 1 2 1 1 1 1 1 1

3 3

1 2 3

3 2 1

Output for Sample Input

Case 1:

001

010

100

Case 2: impossible

Case 3: impossible

Case 4:

001001111

111110000

Case 5:

100

110

111

/***/ Please give some Hint or pseudocode [if needed] /***/

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By abcd1204, 10 years ago, In English

Here is the LINK Please give some hint and [pseudocode(if needed)]

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it