D. Time to go back
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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,显然是一个排列组合,但数据量大,构造组合函数精度容易出问题,因此可以用杨辉三角
vis[i][j]=vis[i-1][j-1]+vis[i-1][j];
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll vis[][],val[],n,m,k,d,t;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
mem(vis);
for(int i=;i<;i++)
{
vis[i][]=;
for(int j=;j<=i;j++)
{
vis[i][j]=(((vis[i-][j-])%MOD)+((vis[i-][j])%MOD))%MOD;
}
}
scanf("%lld",&t);
while(t--)
{
ll ans=,pos=;
scanf("%lld%lld%lld%lld",&n,&m,&k,&d);
for(ll i=;i<n;i++)
scanf("%lld",&val[i]);
sort(val,val+n,cmp);
for(ll i=;i<n;i++)
{
if(val[i]>=d) ans++;
else break;
}
if(n-ans==) pos=vis[ans][m];
else if(ans<k || n<m) pos=;
else
{
for(ll i=k;i<=ans;i++)
{
if(m-i<) break;
pos=(pos+(vis[ans][i]*vis[n-ans][m-i])%MOD)%MOD;
}
}
printf("%lld\n",pos);
}
}

Gym 100952 D. Time to go back的更多相关文章

  1. Gym 100952 D. Time to go back(杨辉三角形)

    D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...

  2. codeforces gym 100952 A B C D E F G H I J

    gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...

  3. Gym 100952 H. Special Palindrome

    http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...

  4. Gym 100952 G. The jar of divisors

    http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...

  5. Gym 100952 F. Contestants Ranking

    http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...

  6. Gym 100952 C. Palindrome Again !!

    http://codeforces.com/gym/100952/problem/C C. Palindrome Again !! time limit per test 1 second memor ...

  7. Gym 100952 A. Who is the winner?

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

  8. Gym 100952 B. New Job

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

  9. 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 ...

随机推荐

  1. python 中的property

    """ property() 的第一个参数是 getter 方法,第二个参数是 setter 方法 xx = property(a,b) @property #用于指示g ...

  2. 【SRM 716 DIV 1 A】 ConstructLCS

    Problem Statement A string S is a subsequence of a string T if we can obtain S from T by erasing som ...

  3. XWIKI的搭建

    原文地址:https://my.oschina.net/gywbest/blog/780569 一 应用背景描述 在平时的运维工作中,把常规工作进行文档整理非常重要,无论是平时工作处理或是工作交接,实 ...

  4. 洛谷 P1583 魔法照片

    P1583 魔法照片 题目描述 一共有n(n≤20000)个人(以1--n编号)向佳佳要照片,而佳佳只能把照片给其中的k个人.佳佳按照与他们的关系好坏的程度给每个人赋予了一个初始权值W[i].然后将初 ...

  5. zookeeper 性能测试

    zookeeper压力测试:性能对比(3个节点,5个节点,7个节点 创建节点.删除节点.设置节点数据.读取节点数据性能及并发性能) 测试结果如下: 五次测试三节点结果: 创建100W节点用时:15.0 ...

  6. 移动端web app开发备忘

    近期要做个手机html5的页面,做些知识储备,重要的点记录下来以备兴许. 1.devicePixelRatio:定义设备物理象素和设备独立象素的比例.css中的px能够看作是设备的独立象素.通过dev ...

  7. ProFTPD 的 mod_lang模块

    ProFTPD 的 mod_lang模块http://www.proftpd.org/docs/modules/mod_lang.html安装该mod_lang模块随ProFTPD一起分发.要在pro ...

  8. google浏览器修改网页字符编码

    google浏览器修改网页字符编码 直接在google浏览器的应用拓展程序里面搜 Charset,第一个就是 于是就有了

  9. ZOJ 2588 Burning Bridges(求桥的数量,邻接表)

    题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2588 Burning Bridges Time Limit: 5 ...

  10. .net数字转换成汉字大写

    public class Num2Rmb { private String[] hanArr={"零","壹","贰","叁&qu ...