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. 常用doc 命令

    开始-->运行 regedit 进入注册表补充些: 1. gpedit.msc-----组策略 2. sndrec32-------录音机 3. Nslookup-------IP地址侦测器 4 ...

  2. Leetcode 665.非递减数列

    非递减数列 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i ...

  3. Hexo安装配置详解

    原文 http://blog.csdn.net/tonydandelion2014/article/details/61615898 http://www.joryhe.com/2016-06-06- ...

  4. 解决IDEA2018.1.5或者Android Studio 3.0版本的输入法不跟随光标问题

    问题1:IDEA2018.1.5版本的输入法不跟随光标 解决办法1:修改JDK版本,步骤如下: 1. 使用快捷键ctrl+shift+A,在输入框中输入Switch Boot JDK,如图所示 2.替 ...

  5. SQL Server 重新编译存储过程的方式有三种

    SQL Server 中,强制重新编译存储过程的方式有三种: sp_recompile 系统存储过程强制在下次执行存储过程时对其重新编译.具体方法是:从过程缓存中删除现有计划,强制在下次运行该过程时创 ...

  6. 多线程 线程池 ExecutorService

    package org.zln.thread; import java.util.Date; import java.util.concurrent.ExecutorService; import j ...

  7. BOZJ 2045:疯狂的馒头(并查集)

    题目大意:有n个馒头排成一排,初始时颜色为0,进行m次染色,第i次将(i*p+q)mod n到(i*q+p)mod n的馒头全部染成颜色i,求最后所有馒头颜色.n<=10^6 m<=10^ ...

  8. Waifu2x测试

    真的是好玩..给大家(?)提供一个能用Waifu2x upscale的图片类型集合.. 上面是原图下面是Upscaled..因为是png大家自行下载对比..

  9. 7月14号day6总结

    今天学习过程和总结 IOC和DIO IOC相当于一个容器,在容器中加注解.接口存在意义依赖注入.4个注解都行,依赖注入只能发生在IOC容器里, pring IOC 容器可以管理Bean 的生命周期,S ...

  10. RHEL退出RHN

    清除原有数据 rm -rf /etc/sysconfig/rhn/rhn_systemidrm -rf /var/cache/yum/*yum clean all 加载刷新源 yum repolist ...