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. 如何通过C#开发调用Skyline软件中提供的小工具

    熟悉Skyline的朋友会知道,在TerraBuilder和TerraExplorer Pro软件的安装目录里,提供了很多个小工具(exe程序): 虽然我们看不到这些小工具的源代码,但我们还是可以在自 ...

  2. OpenGL初学:安装配置与第一个程序

    OpenGL初学:安装配置与第一个程序 2014年10月12日 12:37:03 process-z 阅读数:12413 标签: opengl安装教程 更多 个人分类: OpenGL   计算机图形学 ...

  3. Redis详解(六)------ RDB 持久化

     前面我们说过,Redis 相对于 Memcache 等其他的缓存产品,有一个比较明显的优势就是 Redis 不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,has ...

  4. CF1110E Magic Stones 差分

    传送门 将原数组差分一下,设\(d_i = c_{i+1} - c_i\) 考虑在\(i\)位置的一次操作会如何影响差分数组 \(d_{i+1}' = c_{i+1} - (c_{i+1} + c_{ ...

  5. Codechef MGCHGYM Misha and Gym 容斥、背包、Splay

    VJ传送门 简化题意:给定一个长度为\(N\)的数列,\(Q\)个操作: \(1\,x\,a\).将数列中第\(x\)个元素改为\(a\) \(2\,l\,r\).反转子序列\([l,r]\) \(3 ...

  6. Flask核心机制--上下文源码剖析

    一.前言 了解过flask的python开发者想必都知道flask中核心机制莫过于上下文管理,当然学习flask如果不了解其中的处理流程,可能在很多问题上不能得到解决,当然我在写本篇文章之前也看到了很 ...

  7. Python高级特性(切片,迭代,列表生成式,生成器,迭代器)

    掌握了Python的数据类型.语句和函数,基本上就可以编写出很多有用的程序了. 比如构造一个1, 3, 5, 7, ..., 99的列表,可以通过循环实现: L = [] n = 1 while n ...

  8. 如何写好一篇高质量的IEEE/ACM Transaction级别的计算机科学论文?

    转自<知乎>如何写好一篇高质量的IEEE/ACM Transaction级别的计算机科学论文? 问题: 作为一个博士生,一直为写论文头疼,读过很多高质量论文,觉得写的真好,但是轮到自己写总 ...

  9. Oracle_安装说明

    1.先到Oracle官网上下载11g oracle Database 11g 第 2 版 (11.2.0.1.0) 标准版.标准版 1 以及企业版 适用于 Microsoft Windows (x64 ...

  10. Natural Language Generation/Abstractive Summarization

    调研目的: 了解生成式文本摘要的常用技术和当前的发展趋势,明确当前项目有什么样的摘要需求,判断现有技术能否用于满足当前的需求,进一步明确毕业设计方向及其可行性 调研方向: 项目中需要用到摘要的地方以及 ...