UVA 12712 Pattern Locker(排列的基本应用)

12 篇文章 0 订阅

UVA  12712
Pattern Locker

Mr. Anderson is in a relationship with a very suspicious and jealous girlfriend. She is always checking
Anderson’s phone logs and texts to find out he is up to. Feeling that his private space is getting violated,
he decided to put a pattern locker on his phone.
This pattern locker comes with a 9 dots arranged on a 3x3 square grid by default. One has to
drag through several dots to record a pattern. Then to unlock the phone, one needs to replicate the
same pattern recorded before. If we assume that each dot is assigned a unique number then a pattern
is nothing more than a sequence of digits. The pattern locker requires that no digit appears in the
sequence more than once.
Here is an example of such a pattern locker and some valid and invalid recorded pattern:


Even after recording a hard to crack pattern, Mr. Anderson doesn’t feel quite comfortable. He is
worried that his girlfriend might try all possible sequences to break his pattern. He wants to know how
many different pattern sequences are possible for a given grid size, minimum and maximum numbers
of dots recorded in patterns.
You have to help Mr. Anderson in counting the number of possible such sequences.


Input


The first line of the input will give the number of test cases, T (1 ≤ T ≤ 10000). Then T test cases
follow in separate lines. Each test case consists of three numbers L, M, N separated by a single space
in between two numbers. The first number L (1 < L ≤ 100) denotes the number of rows and columns
in the grid. The second number M (1 ≤ M ≤ L ∗ L) denotes minimum number of dots to be included

in a pattern and the third number N (M ≤ N ≤ L ∗ L) denotes the maximum number of dots to be
included in the pattern.

Output


For each test case, you need to print the test case number X in the format ‘Case X: ’. This will be
followed by the count of possible sequences for the given grid size, minimum and maximum number of
dots in a sequence. Since the count can be pretty big, you need to print the value of the count modulo
10000000000007 (1 followed by 12 zeros followed by 7). There is no new-line between cases.


Sample Input


2
3 4 9
3 1 9


Sample Output


Case 1: 985824
Case 2: 986409

AC代码:

#include <stdio.h>
#define mod 10000000000007
#define ll long long
//author:YangSir
ll f(ll a,ll b){
	ll i,ans=1;
	for(i=a-b+1;i<=a;i++){
		ans*=i;ans%=mod;
	}
	return ans%mod;
}
int main(){
	ll T,l,m,n,i,t=1,ans,ansm,num;
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&l,&m,&n);
		num=l*l;
		ansm=f(num,m);
		ans=ansm;
		for(i=m+1;i<=n;i++){
			ansm*=(num-i+1);ansm%=mod;
			ans+=ansm;ans%=mod;
		}
		printf("Case %lld: %lld\n",t++,ans%mod);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值