Description
给出一个
n×m
的矩阵,现在要给每个位置填数,只能填
±1
,问有多少种方案使得每行每列乘积均为
k
,其中
Input
三个整数 n,m,k(1≤n,m≤1018)
Output
输出方案数,结果模 109+7
Sample Input
1 1 -1
Sample Output
1
Solution
如果
k=1
,先给前
n−1
行前
m−1
列填好数字,每个数组随便填,方案数
2t
,其中
t=(n−1)⋅(m−1)
,然后给前
n−1
行每一行的第
m
个数字填和该行前
如果
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
#define mod 1000000007
int Pow(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)ans=(ll)ans*a%mod;
a=(ll)a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
ll n,m;
int k;
while(~scanf("%I64d%I64d%d",&n,&m,&k))
{
int t=(ll)((n-1)%(mod-1))*((m-1)%(mod-1))%(mod-1);
if(k==1)printf("%d\n",Pow(2,t));
else if(k==-1)
{
if((n+m)&1)printf("0\n");
else printf("%d\n",Pow(2,t));
}
}
return 0;
}