1. 程式人生 > >2016 China Final H Great Cells 貢獻和思想

2016 China Final H Great Cells 貢獻和思想

/**
	Ag其實是很難求的,需要從整體把握

	sigma{(g + 1) * Ag} = sigma{Ag} + sigma{g * Ag},而
		1.sigma{Ag}其實是所有情況
		2.g * Ag = Ag + Ag + ... + Ag ,將g*Ag分攤到g個格子上,
		那麼sigma{g * Ag}其實是每個格子上分攤到的Ag之和
*/
//#include <bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<set>
#define T__ int T;scanf("%d",&T);while(T--)
using namespace std;
typedef long long LL;
const int maxn=100+5;
const int MOD=1e9+7;
LL fast_pow(LL a,LL b){
	LL rst=1;
	for(;b;b>>=1,a=a*a%MOD){
		if(b&1) rst=rst*a%MOD;
	}
	return rst;
}
int main()
{
#ifdef _WY
freopen("0905.in","r",stdin);
#endif // _WY
	ios::sync_with_stdio(false);
	int kase=0;
	LL n,m,k;
	int T;cin>>T;
	while(T--){
		cin>>n>>m>>k;
		LL ans=fast_pow(k,m*n);
		LL x=(n*m%MOD*fast_pow(k,(n-1)*(m-1))%MOD)%MOD;
		LL y=0;
		for(int i=1;i<=k;++i){
			y=(y+fast_pow(i-1,n+m-2)%MOD)%MOD;
		}
		ans=(ans+x*y%MOD)%MOD;
		cout<<"Case #"<<++kase<<": "<<ans<<endl;
	}
    return 0;
}