QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 512 MB مجموع النقاط: 100

#3773. Building Blocks Toys

الإحصائيات

You want to build a toy by placing identical cubic blocks on a rectangular grid. The shape of the toy can be described by a "height matrix." For example, the matrix below indicates that the height above the center cell of the grid is 4, while the height at all other positions is 1.

You have an unlimited supply of $1 \times 1$ and $1 \times 2$ blocks, so you can build many different toys. The figure below shows one possible configuration, where letters represent unit cubes, and identical letters represent the same block.

(a) Top view (b) Front view

If at least one $1 \times 1$ block is used, the toy is called a "regular toy"; otherwise, it is called an "advanced toy."

Given a height matrix, your task is to count how many different regular toys and advanced toys can be formed.

Input

The input contains no more than 20 test cases. The first line of each test case contains two positive integers $R$ and $C$ ($1 \le R \times C \le 16$), representing the number of rows and columns of the grid. The following $R$ lines each contain $C$ integers, representing the height $h(i,j)$ of each cell ($0 \le h(i,j) \le 20$).

Output

For each test case, output the test case number, the number of regular toys, and the number of advanced toys. Since the answers can be very large, output these two values modulo $10^9+7$.

Examples

Input 1

3 3
1 1 1
1 4 1
1 1 1
1 5
1 1 1 1 1
2 2
2 3
4 5

Output 1

Case 1: 485 2
Case 2: 8 0
Case 3: 2794 12

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.