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. 车轮升级PHP7踩过的一些坑

    社区php7升级记录 社区服务器已经全部完成升级,这里记录一下社区升级php7所遇到的问题,可以分为四个类型 扩展支持的变化,导致需要修改配置甚至调整替换操作的类库 php7语法检查比之前变得严格,部 ...

  2. ${pageContext.request.contextPath}的作用【转载】

    原文地址:http://ps329795485-126-com.iteye.com/blog/1290662 刚开始不知道是怎么回事,在网上也查找了一些资料,看了还是晕. 看了另一个大侠的,终于有了点 ...

  3. openssl生成签名与验证签名

    继上一篇RSA对传输信息进行加密解密,再写个生成签名和验证签名. 一般,安全考虑,比如接入支付平台时,请求方和接收方要互相验证是否是你,就用签名来看. 签名方式一般两种,对称加密和非对称加密.对称加密 ...

  4. apache、nginx的虚拟域名配置和rewrite配置,以及web缓存的几种方式

    web缓存一般用来缓解数据库压力. 通常有几种方法,文件静态化,缓存服务memcached.redis等. 伪静态,一般指在url上貌似访问静态html页的形式,这样有利于搜索引擎访问到网站页面,实际 ...

  5. 如何让.NET Core支持GB2312和GBK

    在.NET Core中,默认是不支持GB2312和GBK编码的. 例如我们如果新建一个.NET Core控制台项目,然后在其Main方法中使用如下代码: using System; using Sys ...

  6. [python][spark]wholeTextFiles 读入多个文件的例子

    $pwd /home/training/mydir $cat file1.json {"firstName":"Fred", "lastName&qu ...

  7. JXOI2018简要题解

    JXOI2018简要题解 T1 排序问题 题意 九条可怜是一个热爱思考的女孩子. 九条可怜最近正在研究各种排序的性质,她发现了一种很有趣的排序方法: Gobo sort ! Gobo sort 的算法 ...

  8. SPI内容随笔

    关于SPI的通信: SPI采用的是主从模式的同步通信,通过时钟来控制:一般情况下,使用双向全双工,收发的数据放在缓冲器FIFO中.数据的传输是主SPI的时钟在控制,从机是不能产生时钟的,如果没有时钟, ...

  9. 使用Pyspark进行特征工程时的那些坑

    以脚本spark_clean_online_action.py.数据集new_sxf_time_count_1781115582.csv为例: 集群节点包括212.216.217.218.需要注意的是 ...

  10. Mvc_ActionResult返回值

    //ViewResult 表示HTML的页面内容 //EmptyResult 表示空白的页面内容 //RedirectResult 表示定位到另外一个URL //JsonResult 表示可以运用到A ...