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 题意 一共有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代码

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#define maxn 210
#define mod 1000000007
using namespace std;
typedef long long ll;
ll c[maxn][maxn];
int a[maxn];
void yanghui() //杨辉三角求C几几;
{
memset(c,,sizeof(c));
int i,j;
for(i=;i<maxn;i++)
c[i][]=;
for(i=;i<maxn;i++)
{
for(j=;j<=i;j++)
{
c[i][j]=(c[i-][j-]+c[i-][j])%mod;
}
}
}
int main()
{
int t;
int i,j;
int n,m,k,d;
yanghui();
cin>>t;
while(t--)
{
cin>>n>>m>>k>>d;
int sum=;
ll ans=;
for(i=;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(i=;i<n;i++)
{
if(a[i]>=d)
{
sum++;
}
}
for(i=k;i<=m&&i<=sum;i++)
{
ans=(ans+c[sum][i]*c[n-sum][m-i])%mod;
}
cout<<ans<<endl;
}
}

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. JavaWeb框架_Struts2_(五)----->Struts2的标签库

    1.  Struts2的标签库 1.1 Struts2标签库概述 Struts2的标签库可以分为以下3类:用户界面标签.非用户界面标签.AJAX标签; 2.1.1 Struts2标签库的分类和使用 1 ...

  2. visual studio 2012打开提示 未能将网站×××配置为使用 ASP.NET 4.5 和 尚未在Web服务器上注册,您需要手动将Web服务器配置为使用ASP.NET 4.5

    未能将网站×××配置为使用 ASP.NET 4.5.为了使此网站正确运行,您必须将它手动配置为使用ASP.NET 4.5. ASP.NET 4.5尚未在Web服务器上注册,您需要手动将Web服务器配置 ...

  3. mac下配置caffe

    Step1:安装homebrew 如果电脑上有,暂时不装.但是在step2(或者其他需要brew的情况)加完sudo之后如果仍然报错,就需要重新安装homebrew.在终端里输入如下命令: ruby  ...

  4. MySQL 使用经验

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/10 在索引中完成排序 SELECT thread_id FROM ...

  5. 童话故事 --- 什么是SQL Server Browser

    高飞狗这几天特别郁闷,不知该如何通过TCP/IP协议连接SQL Server数据库.好在功夫不负有心人,经过几天的刻苦研究,终于得到了答案. 高飞狗呼叫UDP1434端口,"叮铃铃,叮铃铃- ...

  6. Java NIO (四) 选择器(Selector)

    选择器(Selector) 是 SelectableChannle 对象的多路复用器,Selector 可以同时监控多个 SelectableChannel 的 IO 状况,也就是说,利用 Selec ...

  7. Python sort方法

    官方文档: sort(*, key=None, reverse=False) This method sorts the list in place, using only < comparis ...

  8. 三:Redis连接池、JedisPool详解、Redisi分布式

    单机模式: package com.ljq.utils; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; ...

  9. Keras 学习之旅(一)

    软件环境(Windows): Visual Studio Anaconda CUDA MinGW-w64 conda install -c anaconda mingw libpython CNTK ...

  10. Java Web高级编程(二)

    使用会话维持状态 一.会话 为了实现关联同一个用户端的多个请求和这些请求之间数据的共享,需要用到会话,会话用于维持请求和请求之间的状态.从服务器的角度,当用户的Web浏览器打开第一个链接到服务器的套接 ...