## DMOPC '14 Exam Time P6 - Math Homework

View as PDF

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem types

One morning, you realize that binary matrices are irresistible. You just can't stop thinking about them. You realize that you had inherited your love of binary matrices from your math teacher, Mr. Sidhu!

Thinking back a little, this is because Mr. Sidhu had left you a homework problem to be completed by last period today. And you didn't even start on it! Luckily, you have a few minutes before class starts. You take a look at the problem again:

Determine the number of binary matrices of size that have at least one 1 entry in each row and column, modulo .

Since there are a lot of problems of this form, specifically of these problems, you would like to write a program that solves these quickly, or risk getting a mark below 100 in math!

#### Input Specification

The first line of input will have the number of test cases, . The next lines will each contain a test case.

Each test case is one line with and separated by a single space.

#### Output Specification

For each test case, output the answer. Remember to take it modulo .

#### Constraints

There will be 5 subtasks each worth 20% of the points for this problem.

#### Tips

Optimize your program to run as fast as possible, even if you think it has the correct complexity.

#### Sample Input

4
1 1
2 2
2 3
3 2

#### Sample Output

1
7
25
25

#### Explanation

The seven matrices for the case are:

11
11

11
10

11
01

10
11

01
11

01
10

10
01

Original Problem Author: No_stop; Problem Resource: HDU 5155

• daoboyang41  commented on Aug. 10, 2018, 11:50 a.m. edited

I wonder how this kid's math teacher's gene is passed on to the kid...

Edit: Never mind. I only read the first paragraph when I wrote it.

• Cueball1234  commented on Sept. 3, 2017, 11:58 p.m. edit 2

Internal Error?

• awaykened  commented on Jan. 13, 2015, 5:25 p.m.

my code works fine on my computer, and i expect it to at least run on the first subtask x.x is there a reason as to why the judge gives an error?

• FatalEagle  commented on Jan. 13, 2015, 5:26 p.m.

random is disallowed on PYPY. It might or might not be fixed soon.

• awaykened  commented on Jan. 13, 2015, 5:27 p.m.

crud, thanks :(

• FatalEagle  commented on Jan. 13, 2015, 5:34 p.m.

It has been fixed. Solutions were rejudged.