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;
}