Matrices with XOR property

    xiaoxiao2021-03-25  75

    Imagine A is a NxM matrix with two basic properties

    1) Each element in the matrix is distinct and lies in the range of 1<=A[i][j]<=(N*M)

    2) For any two cells of the matrix, (i1,j1) and (i2,j2), if (i1^j1) > (i2^j2) then A[i1][j1] > A[i2][j2] ,where

    1 ≤ i1,i2 ≤ N

    1 ≤ j1,j2 ≤ M.

    ^ is Bitwise XOR

    Given N and M , you have to calculatethe total number of matrices of size N x M which have both the properties

    mentioned above.

    Input format:

    First line contains T, the number of test cases. 2*T lines follow with N on the first line and M on the second, representing the number of rows and columns respectively.

    Output format:

    Output the total number of such matrices of size N x M. Since, this answer can be large, output it modulo 10^9+7

    Constraints:

    1 ≤ N,M,T ≤ 1000

    SAMPLE INPUT

    1

    2

    2

    SAMPLE OUTPUT

    4

    Explanation

    The four possible matrices are:

    [1 3] | [2 3] | [1 4] | [2 4]

    [4 2] | [4 1] | [3 2] | [3 1]

    题意 构造一个矩阵,使得在矩阵中ij位置,值为a[i],异或值为i^j,求得比它小的异或值的位置值比它小。且保证矩阵中的数唯一,1~n*m; 暴力做法,三维矩阵异或值图 0 3 2 0 填 1 2 3的排列 为 3! 1填 4 5 2填 6 7 3 0 1 3填 7 8 2 1 0 排列数为 3!*2!*2!*2! 由于1000^1000 最大为 1023 .所以暴力可求。 算出所有的 A!

    #include <bits/stdc++.h> using namespace std; const int maxn=2333; const int mod=1e9+7; const int mm=1e6+7; int n,m; int cnt[maxn]; int fact[mm]; int main() { fact[0]=1; for(long long i=1;i<=1e6;i++) fact[i]=i*fact[i-1]%mod; int T; scanf("%d",&T); while(T--) { memset(cnt,0,sizeof(cnt)); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) cnt[i^j]++; } long long ans=1; for(int i=0;i<1024;i++) { if(cnt[i]) { ans=ans*fact[cnt[i]]%mod; } } printf("%lld\n",ans ); } }
    转载请注明原文地址: https://ju.6miu.com/read-25654.html

    最新回复(0)