#P10692. [SNCPC2024] 表达式矩阵

    ID: 12136 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索2024Special JudgeO2优化陕西XCPC状压 DP

[SNCPC2024] 表达式矩阵

Problem Description

An n×mn \times m character matrix aija_{ij} is called a valid expression matrix if and only if it satisfies the following conditions.

  • The matrix contains only the characters '1', '+', and '*'.

  • The string formed by each row from left to right is a valid expression.

  • The string formed by each column from top to bottom is a valid expression.

The weight of a valid expression matrix is defined as follows: evaluate all n+mn + m expressions formed by each row (left to right) and each column (top to bottom), and take the sum of their values.

Find, among all valid n×mn \times m expression matrices, one with the minimum weight. If there are multiple minimum answers, you may output any one of them.

We define a string ss to be a valid expression as follows.

  • If $s = \overbrace{111\dots111}^{\text{at least one }1}$, then ss is a valid expression.

  • If both ss and tt are valid expressions, then ss * tt is also a valid expression.

  • If both ss and tt are valid expressions, then ss + tt is also a valid expression.

Input Format

The input consists of one line with two integers n,mn, m (3n,m93 \leq n, m \leq 9), separated by a space, representing the number of rows and columns of the matrix.

Output Format

Output nn lines, each containing mm characters. The jj-th character of the ii-th line is aija_{ij}, representing a matrix with the minimum weight.

If there are multiple minimum answers, you may output any one of them.

4 4

1111
1*11
11*1
1111

Hint

For the sample, the weight of the matrix is 44884488. It can be proven that there is no matrix with a smaller weight.

Translated by ChatGPT 5