Cheerleaders UVA - 11806(容斥+组合数学)

思路:正难则反。

const int N = 505;
ll C[N+1][N+1];
void x_x()
{
	C[0][0] = 1;
	f(i, 1, N)
	{
		f(j, 0, i)
		{
			if (!j)C[i][j] = 1;
			else C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
	}
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int t;
	int n, m, k;
	cin >> t;
	int cas = 0;
	x_x();
	while (t--)
	{
		scanf("%d%d%d", &n, &m, &k);
		ll ans = 0;
		f(i, 0, (1 << 4) - 1)
		{
			int cot = 0;
			int r = n, c = m;
			f(j, 0, 3)
			{
				if (j <= 1)
				{
					if (i >> j & 1)
						cot++, r--;
				}
				else {
					if (i >> j & 1)cot++, c--;
				}
			}
			if (cot & 1)ans = (ans - C[r*c][k] + mod) % mod;
			else ans = (ans +C[r*c][k]) % mod;
		}
		printf("Case %d: %lld\n", ++cas, ans);
	}
	return 0;
}

你可能感兴趣的:(基础数论)