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. USACO Section1.1 Broken Necklace 解题报告

    beads解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  2. 小程序使用Canvas画饼图

    先上效果图 -------------------------------------------------------------wxml代码开始------------------------- ...

  3. Jforum环境之Tomcat环境搭建

    Jforum环境搭建,需先安装JDK.JRE.Tomcat.Mysql(JDK.JRE暂不做说明).本文先说Tomcat环境搭建 1.进入Apache Tomcat官网下载,我选择的是免安装的zip包 ...

  4. selenium启动IE浏览器报错:selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode mu

    意思是浏览器的保护模式设置不一致所导致 解决方案-->修改IE设置 将所有区域的保护模式勾选去掉即可

  5. unity灯光Lightmapping、LightProbes

    1.为什么要用Lightmapping? 简单来说就是实时灯光计算十分耗时,随着光源越多,计算耗时会倍增.使用Lightmap模拟灯光带来的效果,便不用去计算灯光,会带来性能上的大大提升. 当然一个复 ...

  6. heat应用

    作为OpenStack中的编排引擎,Heat能够出色的完成编排任务,井井有条地管理编排出来的资源.但同时,Heat也是一个出色的应用部署引擎,它提供了一套内置的框架去完成一系列复杂的应用部署任务. 使 ...

  7. c++ object model

    对一个结构体进行不断的封装后可以形成一个c++类,为此需要添加很多函数成员之类的代码,为此显示c++比c语言显得庞大并且迟缓,但是事实并不是这些 c++在布局和时间上的额外承担主要是由virtual引 ...

  8. 【转】Unity3D 关于贝赛尔曲线,平滑曲线,平滑路径,动态曲线

    http://tieba.baidu.com/p/2460036481 很多时候我们需要的并不是直线和折线,而是平滑的曲线,比如寻路系统,某些物体的曲线运动,都需要平滑曲线来保证效果,今天试了一下,通 ...

  9. jQuery选择器示例

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

  10. [洛谷P4346][CERC2015]ASCII Addition

    题目大意:给一个像素的$a+b$,每个数字为$7\times5$的像素,每两个数字之间有间隔 题解:乱搞读入 卡点:无 C++ Code: #include <cstdio> #inclu ...