ASSIGN  Assignments
Problem
Your task will be to calculate number of different assignments of n different topics to n students such that everybody gets exactly one topic he likes.
Input
First line of input contains number of test cases c (1<=c<=80). Each test case begins with number of students n (1<=n<=20). Each of the next n lines contains n integers describing preferences of one student. 1 at the ith position means that this student likes ith topic, 0 means that he definitely doesn't want to take it.
Output
For each test case output number of different assignments (it will fit in a signed 64bit integer).
Example
Input: 3 3 1 1 1 1 1 1 1 1 1 11 1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 11 0 1 1 1 0 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 1 0 0 0 0 1 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 1 0 1 Output: 6 7588 7426
hide comments
saurabh_38:
20210218 10:20:22
use> unsigned long long


dhruvgheewala:
20210130 12:48:33
@brokeboy, my code having similar complexities, but I am getting TLE. Do you have any clue, I am using a 2d vector and adjacency matrix to store preferences.


ayushpandia:
20210118 14:36:31
Really nice problem 

ant_2001:
20210117 13:11:25
I am using DP+bitmask, long long ......test cases give correct answer but I am still getting WA . Please help! 

lamda_cdm_10:
20201028 14:29:05
Nice problem for people who are starting to learn bitmasks... has a tight time limit ... enjoyed solving it. 

pranavsindura:
20200905 10:50:20
Both top down and bottom up work. 

karankamboj:
20200609 15:14:01
AC when used recursive DP


regex0754:
20200518 00:08:22
During Bitmasking,I just left shifted all masks so that I can use 1 indexing.But this gives TLE while normal 0


brokeboy:
20200508 19:55:04
Works with Time = (2^n)*n*n, Space = (2^n)*n, Fast IO 

cjchirag7:
20200503 10:20:25
DP with bitmasking with state reduction.

Added by:  gawry 
Date:  20051008 
Time limit:  2.997s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 VB.NET 