Matrix Calculation
Practice
5 (3 votes)
Dynamic programming
Algorithms
Easy Medium
Dynamic programming
Problem
44% Success 848 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Mr X, not so good in maths, was trying to solve a problem . It was his homework assignment , so he had to solve the problem in any circumstance. He is unable to solve the problem and therefore asks for your help.

There is a 2D matrix of size N*M containing the numbers from 0 to N-1. You have to find the number of ways in which if one number is chosen from each row, the union of all chosen numbers will be {0,1,2,......N-1}. As the number of ways can be very large, output the answer mod 109+7.

 

CONSTRAINTS

\(1 \le N \le 20\) (N: number of rows)

\(1 \le M \le 10^6\) (M: number of columns)

Each number of the matrix is between 0 and N-1 (Both inclusive)

INPUT

First line contains 2 integers N and M. 

In next N lines, each line contain M space-separated integers.

OUTPUT

Output a single integer denoting the answer to the above problem.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsApprovedEasy-MediumDynamic programming
Points:30
50 votes
Tags:
Applications of Dynamic ProgrammingAlgorithmsDynamic Programming
Points:30
9 votes
Tags:
AlgorithmsEasy-MediumdpDynamic ProgrammingDynamic programming