URAL 1903 Unidentified Ships(大数组合数打表取模)

9 篇文章 0 订阅
5 篇文章 0 订阅

1903. Unidentified Ships

Time limit: 1.0 second
Memory limit: 64 MB
The First Galactic Fleet flagship Eltreum was patrolling near the center of the Milky Way. Unidentified ships appeared in this sector some time ago and the crew of Eltreum kept a close watch on them. All ships have been counted and classified by the Universal Military Classifier, but their mission and identity remained unclear.
Suddenly, after nearly a week of staying at one place the unidentified ships began to move. Some of them went straight into hyperspace, and one of the remaining ships activated a jamming device that rendered Eltreum's radars useless. Visual observation showed that all the remaining ships rushed away from Eltreum, lining up in a chain in non-descending order of their classes: the lightest ships were ahead and the heaviest ships closed the procession. Unfortunately, only one of the ships in this chain has been precisely identified—the one with a jammer device. The classes of the other ships were not identified. But, perhaps, information gained from the visual observation could help infer something about the remaining ships, couldn't it?

Input

The first line contains integers  n and  t that is the number of unidentified ships before and after the hyperjump (1 ≤  t <  n ≤ 5000). The second line contains integers  c 1, …,  c n that are the classes of the ships according to the Universal Military Classifier (1 ≤  c i ≤ 5000). The third line contains integers  k and  x: the number of the identified ship and its position in the chain (1 ≤  k ≤  n;  1 ≤  x ≤  t ). The number of the identified ship is its position in the list in the second line. Chain positions are numbered from the head of the procession, that is, the list begins with the smallest class number.

Output

Output the number of possible sets of the remaining ships modulo 10 9 + 7.

Samples

input output
5 3
2 1 1 3 1
2 3
1
4 2
1 1 1 1
1 2
3

AC代码:

#include <stdio.h>
#include <string.h>
#define ll long long
#define mod 1000000007
int D[5005],q[5005][2505];
int min(int a,int b){
	return a<b?a:b;
}
void ii(){
	int i,j;
	ll sum;
	q[0][0]=1;
	q[1][1]=q[1][0]=1;
	for(i=2;i<=5000;i++){
		q[i][0]=1;
		for(j=1;j<=i/2;j++){
			sum=q[i-1][min(j,i-1-j)];
			sum+=q[i-1][min(j-1,i-j)];
			sum%=mod;
			q[i][j]=sum;
		}
	}
}
int main(){
	int n,t,k,x,i,j,a,b,c,d,f,g;
	ll m,ans;
	ii();
	while(scanf("%d%d",&n,&t)!=EOF){
		for(i=0;i<n;i++)
			scanf("%d",&D[i]);
		scanf("%d%d",&k,&x);
		g=D[k-1];
		a=b=f=0;
		for(i=0;i<n;i++){
			if(i==k-1)
				continue;
			if(D[i]<g)
				a++;
			else if(D[i]>g)
				b++;
			else 
				f++;
		}
		c=x-1;
		d=t-x;
		ans=0;
		for(i=0;i<=f;i++){
			if(i>c)
				break;
			if(a+i<c)
				continue;
			for(j=0;j<=f-i;j++){
				if(j>d)
					break;
				if(b+j<d)
					continue;
				m=q[f][min(i+j,f-i-j)];
				m*=q[a][min(c-i,a-c+i)];
				m%=mod;
				m*=q[b][min(d-j,b-d+j)];
				m%=mod;
				ans+=m;
				ans%=mod;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值