SPOJ VECTAR1
来源:互联网 发布:40周胎儿发育标准数据 编辑:程序博客网 时间:2024/04/29 16:17
大体题意:
问你有多少个矩阵满足(i1,j1) and (i2,j2), if (i1^j1) > (i2^j2) then A[i1][j1] > A[i2][j2]
对1e9+7取模
思路:
当i1^j1 == i2^j2 的时候不能比较大小, 全排列就好了。
因此问题转换为有多少个i1^j1 == i2^j2 的位置,全排列乘起来就好了
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#define Siz(x) (int)x.size()using namespace std;typedef long long LL;const int mod = 1e9+7;int n,m,T;int vis[2048];LL JIE[2048];void init(){ JIE[0] = 1; for (int i = 1; i < 2048 ;++i){ JIE[i] = (JIE[i-1] * i) % mod; }}int main(){ scanf("%d",&T); init(); while(T--){ scanf("%d %d",&n, &m); memset(vis,0,sizeof vis); for (int i = 1; i <= n; ++i){ for (int j = 1; j <= m; ++j){ vis[i^j]++; } } LL ans = 1LL; for (int i = 0; i < 2048; ++i){ if (vis[i]) ans = (ans*JIE[vis[i]]) % mod; } printf("%lld\n",ans); } return 0;}
VECTAR1 - Matrices with XOR property
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]
- SPOJ VECTAR1
- SPOJ VECTAR1 数学
- SPOJ-VECTAR1 Matrices with XOR property(二维BIT/暴力)
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- 数据库审计
- 遗传算法MATLAB
- The member enum Constants2 can only be defined inside a top-level class放置位置不对
- 【工作日志-不可作为参考】关于ES6中的...扩展运算符
- oj中遇到的问题(一)
- SPOJ VECTAR1
- MQTT---HiveMQ源码详解(六)Netty-Handlers总览
- 使用jsonp解决跨域问题
- 170309-Java异常
- Codeforces Round #403 (Div. 2)A+B
- J2SE-2 Java基础程序设计
- 技术人员的职业规划
- hdu 1690 Bus System (有点恶心)
- Python使用libsvm库