Matrices with XOR property
来源:互联网 发布:vivo手机数据恢复软件 编辑:程序博客网 时间:2024/06/07 21:13
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 );}}
- Matrices with XOR property
- Matrices with XOR property
- SPOJ-Matrices with XOR property,暴力打表!
- SPOJ-VECTAR1 Matrices with XOR property(二维BIT/暴力)
- UVa 11360 - Have Fun with Matrices
- OpenCV 3.0 with Java Chapter 2 Handling Matrices
- property value with CGLIB 错误
- Implementing Inclusion Property with SimpleScalar
- xor
- XOR ^
- xor
- xor
- xor
- Codeforces Round #440 (Div. 1) B. Something with XOR Query
- CF 870D. Something with XOR Queries 交互,思维
- CF870D Something with XOR Queries(异或+暴力枚举)
- 64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option.
- 64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option.
- Python笔记---setuptools 、feedparser、pydelicious
- 选课时间
- 第十三章:Java_反射机制
- AndroidStudio的代码转至eclipse
- 分享一个短信轰炸机、呼死你软件
- Matrices with XOR property
- 使用git将本地项目上传到github上面
- 【算法】牛客网模拟题编程部分
- USACO
- artTemplate使用笔记
- the parameter of session timeout
- 创新王国 芬兰 FINLAND
- MySQL中的IN、OUT、INOUT类型
- Java 并发编程知识点学习总结 (1)