加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 03:29:12 所属栏目:大数据 来源:网络整理
导读: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

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("%lldn",ans);
	}
	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读