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
  1. 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
  1. 3
    126
  2.  
  3. 题意 一共有n件礼物,m个朋友,k个好朋友,好朋友的礼物必须超过d 给出n个礼物的价格(都不相同),问选择方案有多少?
    解析 组合数学 令价格大于等于d的数量为sum c[sum][k]*c[n-k][m-k], 显然是错误的,因为会有好多重复的组合,
    比如 100 150 300 50 55)和(100 55 50 150 300)是重复的。

所以 应该是分步 分类(price >= d 的与 < d 的分开算, 这样就不会相同的礼物选2次了)

首先 C[sum][k]        *    C[n - sum][m - k];

然后 C[sum][k + 1]  *    C[n - sum][ m - k - 1];

接着 C[sum][k + 2]  *    C[n - sum][ m - k - 2];

  ......

一直循环到  i<=m&&i<=sum (看代码)

AC代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<cmath>
  5. #include<algorithm>
  6. #define maxn 210
  7. #define mod 1000000007
  8. using namespace std;
  9. typedef long long ll;
  10. ll c[maxn][maxn];
  11. int a[maxn];
  12. void yanghui() //杨辉三角求C几几;
  13. {
  14. memset(c,,sizeof(c));
  15. int i,j;
  16. for(i=;i<maxn;i++)
  17. c[i][]=;
  18. for(i=;i<maxn;i++)
  19. {
  20. for(j=;j<=i;j++)
  21. {
  22. c[i][j]=(c[i-][j-]+c[i-][j])%mod;
  23. }
  24. }
  25. }
  26. int main()
  27. {
  28. int t;
  29. int i,j;
  30. int n,m,k,d;
  31. yanghui();
  32. cin>>t;
  33. while(t--)
  34. {
  35. cin>>n>>m>>k>>d;
  36. int sum=;
  37. ll ans=;
  38. for(i=;i<n;i++)
  39. cin>>a[i];
  40. sort(a,a+n);
  41. for(i=;i<n;i++)
  42. {
  43. if(a[i]>=d)
  44. {
  45. sum++;
  46. }
  47. }
  48. for(i=k;i<=m&&i<=sum;i++)
  49. {
  50. ans=(ans+c[sum][i]*c[n-sum][m-i])%mod;
  51. }
  52. cout<<ans<<endl;
  53. }
  54. }

2017ecjtu-summer training #6 Gym 100952D的更多相关文章

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

  2. Gym 100952 D. Time to go back(杨辉三角形)

    D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. Gym 101047K Training with Phuket's larvae

    http://codeforces.com/gym/101047/problem/K 题目:给定n<=2000条绳子,要你找出其中三条,围成三角形,并且要使得围成的三角形面积最小 思路: 考虑一 ...

  5. Gym - 100676G Training Camp (状压dp)

    G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...

  6. Gym - 100162G 2012-2013 Petrozavodsk Winter Training Camp G. Lyndon Words 暴力枚举

    题面 题意:如果一个字符串的最小表示法是他自己,他就是一个Lyndon Word. 例如  aabcb 他的循环串有 abcba  bcbaa cbaab baabc 其中字典序最小的是他自己 现在给 ...

  7. Gym 101915

    Gym - 101915A  Printing Books 题意:有一本书,从第X页开始,一共用了n位数字,求此书一共多少页.99就是两位数字,100就是三位数字. 思路:直接模拟即可,我用了一个hi ...

  8. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  9. Gym - 100283F F. Bakkar In The Army —— 二分

    题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...

随机推荐

  1. Mybatis-Oralce批量插入方法

    mybatis-Oralce 中批量插入方法一:<insert id="insertBatchSelective" parameterType="java.util ...

  2. 用html和css轻松实现康奈尔笔记(5R笔记)模板

    缘起 人家都说康奈尔笔记法,很好用呢,能抵抗遗忘曲线,让你的笔记事半功倍,有兴趣的同学自行百度哈. 网上有很多现成的模板,下载下来之后吧,看着好像在上面写英文可能更方便一点,行距很小,而且还有网址在上 ...

  3. Spark源码剖析(六):Worker原理与源码剖析

    上篇文章我们剖析了Master的原理和源码,知道了当Master使用资源分配算法将资源分配完成后,就会给对应的Worker发送启动Driver或者Executor的消息,那么Worker收到这些消息后 ...

  4. ES6 Proxy和Reflect (上)

    Proxy概述 Proxy用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种"元编程"(meta programming),即对编程语言进行编程. Proxy可以理 ...

  5. 3、debian8安装和处理

    本博文仅作本人操作过程的记录,留作备忘.自强不息 QQ1222698 本文写于2016年1月10日09:35:45,首先向debian的创始人Ian Murdock表示沉痛惦念! http://bai ...

  6. MySQL index 增删改

    一.前提信息 1.数据库版本 mysql> select version(),user(); +------------+----------------+ | version() | user ...

  7. java 异常处理与返回

    try{ // 1. return ++x; }catch(){ }finally{ //2. x++; } 实际返回值还是 ++x后的结果,因为 ++x 后 x 的值会入栈,作为返回结果: 以上代码 ...

  8. JavaScript的DOM编程--12--innerHTML属性

    innerHTML属性: 1). 浏览器几乎都支持该属性, 但不是 DOM 标准的组成部分. innerHTML 属性可以用来读, 写某给定元素里的 HTML 内容 <html> < ...

  9. spring项目读取配置文件

    Spring项目在运用中读取配置文件有两种方式: 通过项目的配置文件读取 在spring-context.xml里面加入以下代码 在运用到的类里面加入 @Value("#{configPro ...

  10. vue-router源码学习(一)

    因为v3.01版本中的   /src代码使用TypeScript进行书写,我这里仅仅用作模块学习, 具体学习的还是 /dist/vue-router.js 代码. (一)基本使用方式 JS代码 // ...