You have been out of Syria for a long time, and you recently decided to come back. You remember that you have M friends there and since you are a generous man/woman you want to buy a gift for each of them, so you went to a gift store that have N gifts, each of them has a price.

You have a lot of money so you don't have a problem with the sum of gifts' prices that you'll buy, but you have K close friends among your M friends you want their gifts to be expensive so the price of each of them is at least D.

Now you are wondering, in how many different ways can you choose the gifts?

Input

The input will start with a single integer T, the number of test cases. Each test case consists of two lines.

the first line will have four integers N, M, K, D (0  ≤  N, M  ≤  200, 0  ≤  K  ≤  50, 0  ≤  D  ≤  500).

The second line will have N positive integer number, the price of each gift.

The gift price is  ≤  500.

Output

Print one line for each test case, the number of different ways to choose the gifts (there will be always one way at least to choose the gifts).

As the number of ways can be too large, print it modulo 1000000007.

Example

Input
2
5 3 2 100
150 30 100 70 10
10 5 3 50
100 50 150 10 25 40 55 300 5 10
Output
3
126 解题思路:
就是一道很容易的高中排列组合题,放在高中是送分题,结果被卡到比赛结束。
有n个商品,要选m个送人,其中k各人要价格大于d的商品,问有多少种分法。 假设有10个人,送5个,3个要价格高的,
那么有三种情况:
1.贵的选三个,不贵的选两个:c53*c52
2.贵的选四个,不贵的选一个:c54*c51
3.贵的选五个:c55
分法就是 c53*c52+c54*c51+c55
之前写的时候一直不对,要用杨辉三角解,如果直接除的话,分子是很大的必须要取模,但取完模后,分子会小于分母,然后数值就为0,而杨辉三角就没有这种顾虑了,只有加法。。 实现代码:
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9+;
#define ll long long
const int maxx = *1e2+;
ll mod(ll x){
return x-(x/inf)*inf;
} int main()
{
int i,j,n,m,k,d,a,t,cnt;
ll c[maxx][maxx],ans;
memset(c,,sizeof(c));
for(i=;i<maxx;i++){
c[i][] = ;
for(j=;j<=i;j++)
c[i][j] = mod(c[i-][j-]+c[i-][j]);
}
ios::sync_with_stdio();
cin.tie();
cin>>t;
while(t--){
ans = ;cnt=;
cin>>n>>m>>k>>d;
for(i=;i<n;i++){
cin>>a;
if(a>=d)
cnt++;
}
//cout<<ans<<endl;
for(i=k;i<=cnt;i++){
if(n-cnt==) break;
if(m-i<) break;
else
ans=mod(ans+mod(c[cnt][i]*c[n-cnt][m-i]));
//cout<<c[cnt][i]<<" "<<c[n-cnt][m-i]<<endl;
//cout<<ans<<endl;
}
if(n - cnt == ) ans = c[cnt][m];
//ans = mod(C[cnt][k] * C[n - k][m - k]);
if(cnt < k || n < m)
cout<<""<<endl;
else cout<<ans<<endl;
}
return ;
}

2015 HIAST Collegiate Programming Contest D的更多相关文章

  1. Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】

    E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard inp ...

  2. Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】

    F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...

  3. Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】

    J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...

  4. Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】

    I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...

  5. Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】

    H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...

  6. Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】

    G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...

  7. Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】

    D. Time to go back time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  8. Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】

    C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...

  9. Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

    B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...

  10. Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】

    A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard ...

随机推荐

  1. DNS 协议

    DNS 入门 域名系统(英文:Domain Name System,缩写:DNS)是互联网的一项服务.它作为将域名和 IP 地址相互映射的一个分布式数据库,能够使人更方便地访问互联网.DNS 使用 T ...

  2. Luogu3702 SDOI2017 序列计数 矩阵DP

    传送门 不考虑质数的条件,可以考虑到一个很明显的$DP:$设$f_{i,j}$表示选$i$个数,和$mod\ p=j$的方案数,显然是可以矩阵优化$DP$的. 而且转移矩阵是循环矩阵,所以可以只用第一 ...

  3. Nowcoder156F 托米的游戏/CF280C Game on tree 期望

    传送门 题意:给出一棵树,在每一轮中,随机选择一个点将它与它的子树割掉,最后割掉所有点时游戏结束,问游戏期望进行多少轮.$N \leq 10^5$ 和的期望等于期望的和,我们考虑每一个点对最后答案的贡 ...

  4. EZ 2018 06 24 NOIP2018 模拟赛(二十)

    很久之前写的一套题了,由于今天的时间太多了,所以记起来就写掉算了. 这一场尽管T2写炸了,但也莫名Rank4涨了Rating.不过还是自己太菜. A. 环游世界 首先我们先排个序,想一下如果不用走回来 ...

  5. zjoi2018 day1游记

    咕咕咕 upd:看见有人贴上zhihu的问题,那个我早就看到了... 谴责一番题主 @gzy_cjoier 阅读量马上700没想到吧 既然这么火我挂个广告吧 永别,OI 听说有人催更??

  6. 我的物联网项目专题移到网站:http://51jdk.com

    我的物联网项目专题移到网站:http://51jdk.com

  7. .NetCore实践篇:分布式监控Zipkin持久化之殇

    前言 本系列已写了四篇文章,读本篇之前,可以先读前面几篇. 思考大纲:.Net架构篇:思考如何设计一款实用的分布式监控系统? 实践篇一:.NetCore实践篇:分布式监控客户端ZipkinTracer ...

  8. flask_admin 笔记七 扩展功能

    高级功能 1,开启CSRF保护 要将CSRF保护添加到由ModelView实例生成的表单中,请通过指定form_base_class参数在ModelView子类中使用SecureForm类: from ...

  9. [UWP 自定义控件]了解模板化控件(2):模仿ContentControl

    ContentControl是最简单的TemplatedControl,而且它在UWP出场频率很高.ContentControl和Panel是VisualTree的基础,可以说几乎所有VisualTr ...

  10. Linux下绑定网卡的操作记录

    公司采购的服务器安装了双网卡,并进行bond网卡绑定设置,网卡绑定mode共有七种(0~6) bond0.bond1.bond2.bond3.bond4.bond5.bond6. 第一种模式:mod= ...