lightOJ 1005 - Rooks

简单的数学题,排列组合的问题

#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll c(ll m, ll n)
{
	ll ans = 1, i;
	for (i = 1; i <= n ; i++)
	{
		ans *= m - i + 1;
		ans /= i;
	}
	return ans;
}

int main()
{
	std::ios::sync_with_stdio(false);
	ll T, cas = 0;
	cin >> T;
	while (T--)
	{
		ll n, k;
		cin >> n >> k;
		if (k>n)
		{
			printf("Case %lld: 0\n",++cas);
			continue;
		}
		ll res = c(n,k);
		while (k)
		{
			res *= n;
			n--;
			k--;
		}
		printf ("Case %lld: %lld\n",++cas,res);
	}
	return 0;
}


你可能感兴趣的:(C++,排列组合)