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 ;
}

最新文章

  1. .JavaWeb文件上传和FileUpload组件使用
  2. 【leetcode】Valid Palindrome
  3. CacheManager COUNTER
  4. IOS 杂笔- 6(KVC-KVO)
  5. maven加载spring包
  6. 免安装Oracle客户端使用PLSQL Developer 7/8 连接Oracle10/11g
  7. 北大ACM(POJ1010-STAMPS)
  8. iOS狂暴之路---iOS的第一个应用中能学到哪些知识
  9. Arrays.fill方法的陷阱
  10. Altium Designer 09 (Protel)总线使用方法(解决导入PCB无网络标号问题)
  11. Git 1.9.5.msysgit.1
  12. MacVim小试
  13. Python第一天接触心得
  14. Java课程设计——GUI密码生成器201521123035
  15. 分析RunTime执行命令以及得到返回值
  16. 『神坑』DotNetty 内存泄漏 解决办法
  17. SpringBoot之依赖注入DI
  18. python中如何使输出不换行
  19. redis报Cannot allocate memory错误
  20. perl 中的哈希赋值

热门文章

  1. python 经典博客链接
  2. TCP/IP协议---ICMP协议及ping、traceroute
  3. ADO.NET的Connection Timeout和Command Timeout (转载)
  4. 在WPF中使用Caliburn.Micro搭建MEF插件化开发框架
  5. Ionic下的Jpush消息推送与内容显示
  6. Auto-ML之自动化特征工程
  7. C#编程:从控制台读取数字的两种方式
  8. Android环境准备
  9. Web系统页面打印技术实现与分析
  10. 【BUAA软件工程】第一次阅读作业