题目链接

题意:给你三个数n,m,k;让你构造出一个nm的矩阵,矩阵元素只有两个值(1,-1),且满足每行每列的乘积为k,问你多少个矩阵。

解法:首先,如果n,m奇偶不同,且k=-1时,必然无解:

设n为奇数,m为偶数,且首先要满足每行乘积为-1,那么每行必然有奇数个-1,那么必然会存在有偶数个-1.。满足每列乘积为-1,那么每列必然有奇数个-1,那么必然存在奇数个-1.互相矛盾。

剩下的就是有解的情况了。

我们可以在n-1
m-1的矩阵中随意放置-1,1.在最后一列和最后一行控制合法性即可。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
LL mod=1e9+7;
int main(){
ios::sync_with_stdio(false);
LL n ,m ,k;
cin>>n>>m>>k;
if(k==-1&&(n+m)%2==1)return cout<<0,0;
cout<<powmod(powmod(2,n-1,mod),m-1,mod); return 0;
}

Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field 数学的更多相关文章

  1. Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field【数论/组合数学】

    B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input ...

  2. Codeforces Round #447 (Div. 2)E. Ralph and Mushrooms

    Ralph is going to collect mushrooms in the Mushroom Forest. There are m directed paths connecting n  ...

  3. Codeforces Round #447 (Div. 2) 题解 【ABCDE】

    BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...

  4. Codeforces Round #447 (Div. 2)

    我感觉这场CF还是比较毒的,虽然我上分了... Problem A  QAQ 题目大意:给你一个由小写字母构成的字符串,问你里面有多少个QAQ. 思路:找字符串中的A然后找两边的Q即可,可以枚举找Q, ...

  5. codeforces #447 894A QAQ 894B Ralph And His Magic Field 894C Marco and GCD Sequence

    A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的 ...

  6. 【Codeforces Round #447 (Div. 2) B】Ralph And His Magic Field

    | [链接] 我是链接,点我呀:) [题意] 给你一个n*m矩阵,让你在里面填数字. 使得每一行的数字的乘积都为k; 且每一列的数字的乘积都为k; k只能为1或-1 [题解] 显然每个位置只能填1或- ...

  7. Codeforces Round #447 (Div. 2) 题解

    A.很水的题目,3个for循环就可以了 #include <iostream> #include <cstdio> #include <cstring> using ...

  8. Codeforces Round #447 (Div. 2) C 构造

    现在有一个长度为n的数列 n不超过4000 求出它的gcd生成set 生成方式是对<i,j> insert进去(a[i] ^ a[i+1] ... ^a[j]) i<=j 然而现在给 ...

  9. Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence【构造/GCD】

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. maven 出现错误 -source 1.5 中不支持 diamond 运算符

    mvn clean package -DskipTests 出现如下错误: -source 1.5 中不支持 diamond 运算符 [ERROR] (请使用 -source 7 或更高版本以启用 d ...

  2. Jenkins之Job建立-运行本地脚本

    新建一个自由风格的项目,运行本地脚本 1.点击菜单栏中的“新任务” 2.进入该页面后输入一个项目名称,然后选择“构建一个自由风格的软件项目”,滑动到最底端,点击ok(在左下角) 3.进入下图页面后 “ ...

  3. 转://11g之后,通过v$wait_chains视图诊断数据库hang和Contention

    1g之前,通常我们数据库hang住了之后,我们会对数据库做hang analyze来进行分析,在11g之后,我们可以通过一个新的视图v$wait_chains来诊断数据库hang和contention ...

  4. 数据采集工具Telegraf:简介及安装

    接着上一篇博客:InfluxDB简介及安装,这篇博客介绍下Linux环境下Telegraf安装以及其功能特点... 官网地址:influxdata 官方文档:telegraf文档 环境:CentOS7 ...

  5. 解决 Intellij IDEA Cannot Resolve Symbol ‘XXX’ 问题

    1.java类报错 https://blog.csdn.net/qq_32040767/article/details/77096680 2.类对应的依赖没有加载进来.编译器自身的设置和缓存问题类. ...

  6. Java HttpClient4.5.2发送post请求示例

    public static Map<String, Object> invokeCapp(String URL, Map paramMap) throws Exception { Map ...

  7. DisplayAttribute没作用,why?

    namespace WebBulletinBoard.DataAccess { using System; using System.ComponentModel.DataAnnotations; u ...

  8. Command "python setup.py egg_info" failed with error code 1 in c:\users\w5659\appdata\local\temp\pip-build-fs2yzl\ipython\

    Error Msg: Collecting ipython Using cached https://files.pythonhosted.org/packages/5b/e3/4b3082bd7f6 ...

  9. Python之使用转义序列 \n 和 \t 跟 expandtabs 函数输出表格

    示例: text = "username\temail\tpassword\nashdfh\tfiodfh@q.com\ty567\nsdfiuh\tadfhisoj@163.com\t42 ...

  10. SQLiteOpenHelper+ContentProvider的使用

    效果图: PetDbHelper package com.example.admin.pets; import android.content.Context;import android.datab ...