zoukankan      html  css  js  c++  java
  • Codeforces 894B

    894B - Ralph And His Magic Field

    思路:

    当k为1时,如果n和m奇偶性不同,那么没有答案。

    可以证明,在其他情况下有答案,且答案为2^(n-1)*(m-1),因为前n-1行和m-1列确定后,最后一列和最后一行可以确定,且确定的最后一格不矛盾。

    可以采用在全为1的格子中把一些1换成-1的方法来证明以上两条结论。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define mp make_pair
    #define pii pair<int,int>
    #define mem(a,b) memset(a,b,sizeof(a))
    
    const int MOD=1e9+7;
    ll qpow(ll n,ll k)
    {
        ll ans=1;
        while(k)
        {
            if(k&1)ans=(ans*n)%MOD;
            n=(n*n)%MOD;
            k>>=1;
        }
        return ans;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll m,n;
        int k;
        cin>>m>>n>>k;
        if(k==1)
        {
            cout<<qpow(2,((m-1)%(MOD-1))*((n-1)%(MOD-1)));
        }
        else
        {
            if((m+n)&1)
            {
                cout<<0<<endl;
                return 0;
            }
            cout<<qpow(2,((m-1)%(MOD-1))*((n-1)%(MOD-1)));
        }
        return 0;
    }
  • 相关阅读:
    自定义长时间定时器对象
    poj1326
    poj1323
    poj1218
    poj1298
    poj1276
    新年的第一场雪
    Java 语言学习总结
    假使时光能够倒转
    为了回家——春运3日战纪实
  • 原文地址:https://www.cnblogs.com/widsom/p/7872952.html
Copyright © 2011-2022 走看看