首页 > 其他分享 >CF894B 翻

CF894B 翻

时间:2022-12-11 11:59:12浏览次数:52  
标签:even fp ll ret CF894B odd mod

my

[[math]]
link

First, it's obvious that the numbers put can be only 1 or -1.

If k equals to -1 and the parity of n and m differ, the answer is obviously 0.

Assume that \(n\) is even and \(m\) is even, the count of -1 equals to \(n*odd\) (even) and \(m*odd\) (odd), and it is impassible to be odd and even at the same time.

Otherwise, for the first n-1 lines and the first m-1 columns, we can put either 1 or -1 in it,
and there're \(2^{(n - 1) * (m-1)}\) ways in total.

Then it's obvious that the remaining numbers are uniquely determined because the product of each row and each column is known already.

So in this case the answer is \(2^{(n - 1) * (m-1)}\) .

We can use fast power, which is easy.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,m,ret;
int k;
ll fp(ll x,ll a){
	for(ret=1;a;a>>=1){
		if(a&1)(ret*=x)%=mod;
		(x*=x)%=mod;
	}
	return ret;
}
int main(){
	scanf("%lld%lld%d",&n,&m,&k);
	if(!~k&&(n&1)!=(m&1))printf("0"),exit(0);
	printf("%lld",fp(fp(2,n-1),m-1));
} 

(If the code is very long, I'll leave a link.)

2022.3.28

标签:even,fp,ll,ret,CF894B,odd,mod
From: https://www.cnblogs.com/-WD-/p/16973117.html

相关文章