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

Gym 100952 D. Time to go back(杨辉三角形)的更多相关文章

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

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

  2. Gym 100952 H. Special Palindrome

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

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

  4. Gym 100952 F. Contestants Ranking

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

  5. Gym 100952 D. Time to go back

    http://codeforces.com/gym/100952/problem/D D. Time to go back time limit per test 1 second memory li ...

  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. 一天搞定CSS:BFC布局与普通文档流布局比较--15

    BFC:Block Formatting Contexts–块级元素格式化上下文 1.BFC定义 它决定了块级元素如何对它的内容进行布局,以及与其它元素的关系和相互作用 关键词解释: 块级元素:父级( ...

  2. Sql的连接表补充

        连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件.WHERE和HAVING子句也可以包含搜索条件,以进一步筛选连接条件所选的行.             连接可分为 ...

  3. React-Native集成到已有项目中的总结

    安装Python 从官网下载并安装python 2.7.x(3.x版本不行) 安装node.js 从官网下载node.js的官方V6.X.X版本或更高版本.安装完成后检测是否安装成功:node -v ...

  4. java基础(四章)

    一.             switch结构(开关语句)的语法 switch(表达式 ){ ------- [dream1]类型为int.char case  常量1 :    ---------[ ...

  5. 抓包工具-Wireshark(详细介绍与TCP三次握手数据分析)

    功能使用的详细介绍 wireshark(官方下载网站: http://www.wireshark.org/),是用来获取网络数据封包,可以截取各种网络封包,显示网络封包的详细信息,包括http,TCP ...

  6. html5中cookie介绍,封装以及添加,获取,删除

    cookie是储存在用户本地终端上的数据. 在我们登陆网站时有记录密码,也有时间限制比如说7天,5天等等这都是我们利用cookie来写的, 这就是利用了cookie的会话周期,但cookie同时又是不 ...

  7. [codeforces167B]Wizards and Huge Prize

    B. Wizards and Huge Prize time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  8. .NET和JAVA 反射对比

    反射是一个程序集发现及运行的过程,通过反射可以得到*.exe或*.dll等程序集内部的信息.使用反射可以看到一个程序集内部的接口.类.方法.字段.属性.特性等等信息.在System.Reflectio ...

  9. Mac下安装MySQL、Workbench以及建数据库建表最基础操作

    刚用上Mac,什么都不懂,加之以前还没有用过mysql,就想着在Mac上装一个mysql来自己玩,奈何,在网上找了大半天,没有一个干货!愤怒!下面是我安装的过程,希望能帮到和我情况差不多的朋友   首 ...

  10. JavaScript事件(二)

    例题顺序: 1.子菜单下拉2.图片轮播3.选项卡效果4.进度条制作5.滑动效果6.滚动固定效果 1.子菜单下拉 <!DOCTYPE html PUBLIC "-//W3C//DTD X ...