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. SQL Server 中函数的理解总结

    T-SQL语言为我们提供了更加灵活的方式操作数据,那就是函数,函数总的分为三大类:标量函数:(传入一个参数,再传出一个参数)聚合函数(传入多个参数,传出一个参数),表值函数(传入一个结果集对象,让我们 ...

  2. 每天一个JS 小demo之商品下架特效制作,主要知识点:定时器,倒计时,抖动特效。PS:由于不方便上传文件夹,只能上传效果图,图片等素材需自寻哟。

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. 两强相争,鹿死谁手 — JQuery中的Ajax与AngularJS中的$http

    一.JQuery与AngularJS 首先,先简单的了解一下JQuery与AngularJS.从源头上来说,两者都属于原生JS所封装成的库,两种为平行关系. 二.Ajax请求与数据遍历打印 这里是Aj ...

  4. 使用 libdvm.so 内部函数dvm* 加载 dex

    首先要清楚,odex只是对代码段(我将dex文件与elf文件类比,大家都将执行文件分成不同的段)作优化,而其它用于类反射信息的段都应用原来的dex,所以odex文件内部还包含了一个dex. 打开一个d ...

  5. websocket学习和使用

    1)WebSocket介绍 HTML5 Web Sockets规范定义了Web Sockets API,支持页面使用Web Socket协议与远程主机进行全双工的通信.它引入了WebSocket接口并 ...

  6. asp.net mvc中html helper的一大优势

    刚上手这个框架,发现其中的html helper用起来很方便,让我们这些从web form 过渡来的coder有一种使用控件的快感,嘻嘻! 言归正传,我要说的是在使用它时,系统会自动执行表单的现场恢复 ...

  7. JQuery源码阅读记录

    新建html文件,在浏览器中打开文件,在控制台输入consoole.log(window);新建html文件,引入JQuery后在浏览器中打开,在控制台同样输入consoole.log(window) ...

  8. 如何用php实现文件上传与显示

    首先,我们要创建一个前台页面用于操作选择文件等: <body> <div id="div1"></div> <form action=&q ...

  9. Mac远程连接windows报错“证书或相关链无效,是否仍要连接到此计算机”的处理办法。

    这个主要是因为策略组设置的问题.详细的设置方法如下: 本地计算机策略>计算机配置>管理模板>windows组件>远程桌面服务>远程桌面会话主机>安全>远程(R ...

  10. mysqldump 用法总结

    mysqldump 备份 备份数据库 my_database $ mysqldump -uUSER -pPASSWD my_database > my_database.sql 备份数据库 my ...