codeforces 894B Ralph And His Magic Field
来源:互联网 发布:nginx tomcat 配置ssl 编辑:程序博客网 时间:2024/05/01 16:13
Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.
Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.
Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.
The only line contains three integers n, m and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).
Print a single number denoting the answer modulo 1000000007.
1 1 -1
1
1 3 1
1
3 3 -1
16
In the first example the only way is to put -1 into the only block.
In the second example the only way is to put 1 into every block.
题意:构造一个n*m的矩阵,使得矩阵每一行每一列的乘积都为K,K=+-1,求有多少种构造方法
找规律,每一行的数的乘积为k,一共有2^(m-1)种(假如k=1,C0k+C2k+C4k+....... +=2^(m-1),k=-1结果一样),n-1行的数可以任意填,只用最后一行来补就行,所以一共有(2^(n-1))^(m-1)种方法,当m+n为奇数且k=-1时,要特判0
#pragma comment(linker,"/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,mi#define rson rt<<1|1,mi+1,r#define it rt,l,r#define root 1,1,n#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;const int mod=1e9+7;ll m,n;ll quick(ll x,ll y){ ll ans=1; while(y) { if(y&1)ans=ans*x%mod; y>>=1; x=x*x%mod; } return ans;}int main(){ int a; while(cin>>m>>n>>a) { if((m+n)&1&&a==-1) { puts("0"); continue; } ll p=quick(quick(2,m-1),n-1); pf("%I64d\n",p); } return 0;}
- Codeforces 894B Ralph And His Magic Field
- Codeforces 894 B. Ralph And His Magic Field
- codeforces 894B Ralph And His Magic Field
- codeforces-894B Ralph And His Magic Field
- codeforces 894B. Ralph And His Magic Field
- 894B. Ralph And His Magic Field
- codeforces B. Ralph And His Magic Field 数学题+快速幂
- codeforces 894B. Ralph And His Magic Field (数学题+思维)
- Ralph And His Magic Field
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field(数论,组合数学)
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field(思维)
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field(数学???)
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 推规律+证明
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field
- Codeforce 894B Ralph And His Magic Field (思维+快速幂)
- Codeforces894B-Ralph And His Magic Field
- sizeof和strlen的区别
- 将表单你序列化为json对象
- n皇后问题的递归解法
- 个人知乎 ##基础四-多线程
- MYSQL——自定义函数
- codeforces 894B Ralph And His Magic Field
- AB1601定时器1注意事项
- sublime配置ESLint_Linting React/JSX and ES6 Javascript with Eslint in Sublime Text 3
- 浏览器缓存机制
- 个人知乎 ##功能三-评论中心
- Linux-C标准输入输出
- 671. Second Minimum Node In a Binary Tree
- 个人知乎 ##功能四-站内信
- 2017/11/24(网络)