Gym 101194 思维计数

这个题我一眼看过去真的没有思路啊。。。一堆东西的求和都是啥,如何计算互相的影响真的想的头都不行了,感觉是个思维题,可能是我这方面做的太少了吧,想不出来把等式拆开,这个题就是把g和1拆开看,关键就是这个个数g乘上了Ag,也就是说,有g个好格子的情况才算g贡献值,这个地方很关键:这等同于一个好格子对应一个贡献值,也就是说,你一个格子是好格子,无论其他的怎么选,它的贡献一直都是1,所以你计算每一个格子的贡献就行了,把这个当好格子,同行同列有限制,其他的任意就可以了。干,这题竟如此简单我还不会,其实特征给的很明显了,其中的因子有一个是个数g,一定有蹊跷的,线索已经摆在脸上了啊!!!mmp,中间还没算内n==1和m==1的情况错了,没有考虑连乘爆ll又错了,下次注意!!!

#include<iostream>
#include<cstring>
#include <string>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#define lson rt<<1
#define rson rt<<1|1
using namespace std;
typedef long long ll;
const int maxn=1e5+20;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
ll ans;
ll n,k,m;
int main()
{
    int T,num=1;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>k;
        if(n==1&&m==1)
        {
            ans=k*2;
            cout<<"Case #"<<num++<<": "<<ans<<endl;
            continue;
        }
        ll ans=1,tt=1;
        for(int i=0;i<n*m;i++)
            ans=(ans*k)%mod;
        for(int i=0;i<(n-1)*(m-1);i++)
            tt=(tt*k)%mod;
        
        for(int i=2;i<=k;i++)
        {
            ll t=1;
            for(int j=0;j<n-1;j++)
                t=t*(i-1)%mod;
            for(int j=0;j<m-1;j++)
                t=t*(i-1)%mod;
            ans=(ans+((t*m*n)%mod)*tt)%mod;
        }
        cout<<"Case #"<<num++<<": "<<ans<<endl;
    }
}
原文地址:https://www.cnblogs.com/King-of-Dark/p/11621968.html