Cheerleaders UVA11806

容斥原理


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>   
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;
using std::endl;

const int MOD(1000007);

int count(int sour)
{
	int ret = 0;
	while(sour)
	{
		++ret;
		sour ^= sour&(-sour);
	}
	return ret;
}

int C[410][410];

int main()
{
	C[0][0] = 1;
	for(int i = 1; i <= 400; ++i)
	{
		C[i][0] = C[i][i] = 1;
		for(int j = 1; j < i; ++j)
			C[i][j] = (C[i-1][j]+C[i-1][j-1])%MOD;
	}
	int T;
	int m, n, k;
	int n_case(0);
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d%d%d", &m, &n, &k);
		int tm, tn;
		long long ans = 0LL;
		for(int i = 0; i < 16; ++i)
		{
			tm = m;
			tn = n;
			if(i&1)
				--tm;
			if(i&2)
				--tm;
			if(i&4)
				--tn;
			if(i&8)
				--tn;
			if(tm*tn < k)
				continue;
			ans = (ans+(count(i)&1? -1LL: 1LL)*C[tm*tn][k]+MOD)%MOD;
		}
		cout << "Case " << ++n_case << ": " << ans << "\n";
	}
	return 0;
}



你可能感兴趣的:(Cheerleaders UVA11806)