矩阵
题目链接:http://acm.uestc.edu.cn/#/problem/show/1805
Description
小明发现了一种特殊的\(N×M\)的矩阵,矩阵里的元素都是\(1\)或\(−1\)。假设\(A_i=第i行(1≤i≤N)所有元素的乘积\),\(B_j=第j列(1≤j≤M)所有元素的乘积\)。喜欢搞事情的小明突发奇想,想知道有多少个不相同的,大小为\(N×M\)的矩阵使得所有\(A_i,B_j\)都是\(K\)的(\(K=1或者−1\))。
当且仅当两个矩阵存在一个元素不相同时两个矩阵不相同。
Input
输入只有一行,三个数字\(N,M,K\)。(\(1≤N≤6,1≤M≤7,K=1或者−1\))
Output
输出一个数字,即满足条件的不同矩阵的数量
Sample Input and Output
Sample Input | Sample Output |
---|---|
2 2 1 | 2 |
Hint
这两个不同的矩阵分别是
1 1
1 1
和
-1 -1
-1 -1
题意
http://www.cnblogs.com/scidylanpno/p/7978086.html
题解
(数据量小这题是暴力过去的=-=标准解法参考 http://www.cnblogs.com/scidylanpno/p/7978086.html)
#include
using namespace std;
const int MAXN = 1<<9;
int N,M,K;
int Keep[10][MAXN];
int XOR(int v)
{
int ans=1;
while(v)
{
if(v&1) ans=-ans;
v>>=1;
}
return ans;
}
int GetAns(int m,int st)
{
if(Keep[m][st]!=-1) return Keep[m][st];
if(m==1)
{
if(XOR(st)==K) return Keep[m][st]=1;
return Keep[m][st]=0;
}
int ans=0,mm=m/2;
for(int i=0;i<(1<>N>>M>>K;
int st;
if(K==-1) st=(1<
版权所有:scidylanpno
原文链接:http://www.cnblogs.com/scidylanpno/p/7978069.html