zoukankan      html  css  js  c++  java
  • codeforces-894B Ralph And His Magic Field

    B. Ralph And His Magic Field
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    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.


    Input
    The only line contains three integers n, m and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).


    Output
    Print a single number denoting the answer modulo 1000000007.


    Examples
    input
    1 1 -1
    output
    1
    input
    1 3 1
    output
    1
    input
    3 3 -1
    output
    16
    Note
    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列的矩阵只能由1和-1组成,每行每列的和为x(1或-1)的组合方式有多少种。

    思路:当x=1的时候,每一行和每一列的组合都可以用最后一个1或者-1来让结果等于1。所以组合方式就是2的(n-1*m-1)次方。当x=-1的时候如果m%2和n%2不想等的话,每一行的和肯定不等于每一列的和。所以是0。

    #include<stdio.h>
    #include<iostream>
    #include<algorithm>
    #include<string.h>
    #include<string>
    #include<map>
    #define ll long long
    using namespace std;
    ll mod=1000000007;
    int main()
    {
        ll m,n,k;
        cin>>m>>n>>k;
        if(m%2!=n%2&&k==-1)
        {
            cout<<0<<endl;
            return 0;
        }
        n--;m--;
        n%=mod-1;
        m%=mod-1;
        //cout<<n<<m<<endl;
        ll x=2,ans=1,b=n*m;
        //cout<<b<<endl;
        while(b)
        {
            if(b%2==1)
            {
                ans=ans*x%mod;
                //ans%=mod;
            }
            x=x*x%mod;
            b/=2;
        }
        ans%=mod;
        cout<<ans<<endl;
    }





  • 相关阅读:
    laravel-excel maatwebsite/excel 新版中文文档
    laravel-excel.com官网英文站
    composer查看镜像地址
    Navicat Premium 通过ssh 连接服务器
    Centos7 yum 出现could not retrieve mirrorlist 最终解决方案
    php 获取随机字符串算法
    apache 配置多域名访问的方法
    laravel 配置多域名最简单的方法
    es6知识点
    如何判断浏览器为ie10以上
  • 原文地址:https://www.cnblogs.com/da-mei/p/9053291.html
Copyright © 2011-2022 走看看