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,因为你足够土豪,不用担心钱的问题,然后就是剩下的M-K个人可以买贵的,也可以买便宜的。看你心情,问,一共有多少种买礼物的方法。

要注意,那K个人的礼物价格一定要>=D,否则你就不买了,嗯,就这样。

这个题就是排列组合(组合数)的问题,如果一个一个算的话肯定是不可以的,杨辉三角是个好东西,可以用来处理组合数。

一开始不懂为什么杨辉三角可以用来处理组合数,然后就学了一下杨辉三角,老祖宗就是厉害%,杨辉三角原来这么厉害,传送门:http://www.cnblogs.com/ZERO-/p/7219934.html#3741238

看懂之后就好说了,然后就是代码,有一个坑点,再加上细节处理的不好,导致我wa了20多遍,还是看着大佬的才知道哪里错了,%大佬(托脸)。

先贴代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e3+;
typedef long long ll;
const ll mod=;
ll yh[N][N];
int a[N];
bool cmp(int a,int b){
return a>b;
}
void yanghui(){
memset(yh,,sizeof(yh));
for(int i=;i<;i++){
yh[i][]=;
for(int j=;j<=i;j++)
yh[i][j]=(yh[i-][j-]+yh[i-][j]+mod)%mod;
}
}
int main(){
int t,n,m,k,d,num;
ll ans;
scanf("%d",&t);
yanghui();
while(t--){
scanf("%d%d%d%d",&n,&m,&k,&d);
num=;ans=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>=d)num++;
}
sort(a,a+n,cmp);
if(n-num==)ans=yh[n][m]%mod;
else if(num<k||n<m)ans=; //这里就是如果不符合条件就是0。
else{
for(int i=k;i<=min(num,m);i++){//wa在这里了,i<=min(num,m),因为不知道到底是贵的礼物先选完还是m个人都能买到贵的。
ans=(ans+(yh[num][i]%mod)*(yh[n-num][m-i]%mod))%mod;
}
}
printf("%I64d\n",ans);
}
return ;
}

好啦,先这样吧,后面的还没补呢,慢慢补吧,咸鱼加油~

把wa掉的代码改好之后真的会让人感觉世界都美好了。。。

٩(๑❛ᴗ❛๑)۶

Codeforces Gym100952 D. Time to go back-杨辉三角处理组合数 (2015 HIAST Collegiate Programming Contest)的更多相关文章

  1. Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)

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

  2. Codeforces Gym100952 B. New Job (2015 HIAST Collegiate Programming Contest)

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

  3. Codeforces Gym100952 C. Palindrome Again !!-回文字符串 (2015 HIAST Collegiate Programming Contest)

      C. Palindrome Again !!   time limit per test 1 second memory limit per test 64 megabytes input sta ...

  4. Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】

    D. Time to go back time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  5. java实现组合数_n!_杨辉三角_组合数递推公式_回文数_汉诺塔问题

    一,使用计算机计算组合数 1,设计思想 (1)使用组合数公式利用n!来计算Cn^k=n!/k!(n-k)!用递推计算阶乘 (2)使用递推的方法用杨辉三角计算Cn+1^k=Cn^k-1+Cn^k 通过数 ...

  6. CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A.水题 100952B.水题 100952C.回文字符串 100952D.杨辉三角处理组合数 其他题目待续。。。

    哈哈哈哈哈哈哈,最近一直在补题,改各种错误的代码,wa了20多遍,改到心态爆炸,改好之后,感觉世界都美好了(叉会腰~)... A. Who is the winner? time limit per ...

  7. POJ 3187 全排列+杨辉三角(组合数)

    思路: next_permutation()加个递推组合数随便搞搞就A了- //By SiriusRen #include <cstdio> #include <algorithm& ...

  8. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  9. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

随机推荐

  1. 腾讯装扮下拉选项卡特效(QQ空间)

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

  2. SQL Server 分组取 Top 笔记(row_number + over 实现)

    先看SQL语句(注意:这是在SQL Server 2005+ [包括2005] 的版本才支持的哦,o(∩_∩)o 哈哈~) SELECT col1,col2,col3 FROM table1 AS a ...

  3. Python 实现MD5加密

    from hashlib import md5 def encrypt_md5(s): # 创建md5对象 new_md5 = md5() # 这里必须用encode()函数对字符串进行编码,不然会报 ...

  4. python小结

    c:\python33添加到你的PATH 环境变量中,你可以在DOS 窗口中 输入以下命令:set path=%path%;C:\python33 id() 方法的返回值就是对象的内存地址. 在#! ...

  5. python_ 运算符与分支结构

    # 运算符与分支结构 ### 运算符 - 赋值运算符 - 用'='表示,左边只能是变量. - 算术运算符 - +.-.*:加.减.乘 - /:除法运算,结果是浮点数 - //:除法运算,结果是整数 - ...

  6. GCC特性之__init修饰解析 - kasalyn的专栏 - 博客频道 - CSDN.NET

    , GCC特性之__init修饰解析 - kasalyn的专栏 - 博客频道 - CSDN.NET.MathJax_Hover_Frame {border-radius: .25em; -webkit ...

  7. Android Service完全解析

    Service的基本用法 1.新建一个Android项目,新建一个MyService继承自Service,并重写父类的onCreate(),onStartCommand()方法和onDestory() ...

  8. GCD 开发详情

    目录 一.简介 二.dispatch Queue - 队列 三.dispatch Groups - 组 四.dispatch Semaphores - 信号量 五.dispatch Barriers ...

  9. shit element ui

    shit element ui element ui & select change event demo https://element.eleme.io/#/en-US/component ...

  10. WebIDE

    1 1 1 WebIDE 是什么? WebIDE 是 一款在线集成开发环境( Integrated Development Environment ). 开发者只需要一个浏览器就可以编写代码,并在We ...