首页 > 代码库 > UVA 12712 Pattern Locker(简单排列组合数学题)

UVA 12712 Pattern Locker(简单排列组合数学题)

转载请注明出处:http://blog.csdn.net/u012860063


题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4450


不懂取模运算的请猛戳:http://baike.baidu.com/link?url=A86lTLorv-Mim9g6v8EW3mY98qLz10cot1UCt6TZNPDJyslVYS5Ya1KxLv71bJg_8vFxQXV6Ss5uwzdMQLyi4a



代码如下:


#include <cstdio>
int main()
{
	int n, minn, maxx;
	int t, cas = 0, i, j,tt;
	long long sum = 0, tmp, mod = 10000000000007;
	while(~scanf("%d",&t))
	{
		while(t--)
		{
			scanf("%d%d%d",&n,&minn,&maxx);
			
			sum = 0, tt = n*n, tmp = 1;
			for(i = 1; i <=minn; i++)
			{
				tmp*=tt;
				tmp%=mod;
				tt--;
			}
			sum = tmp%mod;
			for(i = minn+1; i <= maxx; i++)
			{
				tmp*=tt;
				tmp%=mod;
				tt--;
				sum+=tmp;
				sum%=mod;
			}
			printf("Case %d: %lld\n",++cas,sum);
		}
	}
	return 0;
}