D - Time to go back

 Gym - 100952D 

http://codeforces.com/gym/100952/problem/D

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


题意:T组样例,每组样例第一行n个价格,m个好友,k个亲密好友,亲密好友最小的价格是d,第二行是这n个价格
思路:就是排列组合嘛,关键是求组合数,在这里我开始的话是写了一个函数求,最后发现过不了,因为数据太大,精度会出现问题,所以我们要用到杨辉三角形
yanghui[i][j]=(vis[i-1][j-1])+((vis[i-1][j])
代码如下:

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int a[205];
#define MOD 1000000007
long long sum,vis[210][210];
int aa(int n,int m)
{
if(m==0)
return 1;
int s=1,g=1;
for(int i=n;i>=n-m+1;i--)
s*=i;
for(int i=1;i<=m;i++)
g*=i;
return s/g;
}
int main()
{

for(int i=0;i<210;i++)
{
vis[i][0]=1;
for(int j=1;j<=i;j++)
{
vis[i][j]=(((vis[i-1][j-1])%MOD)+((vis[i-1][j])%MOD))%MOD;
}
}
int t;
cin>>t;
while(t--)
{
int n,m,k,d,xia=0,shang=0;
cin>>n>>m>>k>>d;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{

cin>>a[i];
if(a[i]>=d)
xia++;
else
shang++;
}
int i=0;

sum=0;


while(xia-i>=k)
{
if(m-xia+i>=0)
{

sum=(sum+(vis[xia][xia-i]*vis[shang][m-xia+i])%MOD)%MOD; }
i++;

}


cout<<sum<<endl;
}
}