2017ecjtu-summer training #6 Gym 100952D

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,0,sizeof(c));
    int i,j;
    for(i=0;i<maxn;i++)
        c[i][0]=1;
    for(i=1;i<maxn;i++)                                          
    {
        for(j=1;j<=i;j++)
        {
            c[i][j]=(c[i-1][j-1]+c[i-1][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=0;
        ll ans=0;
        for(i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        for(i=0;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;
    }
}

 

转载于:https://www.cnblogs.com/stranger-/p/7207407.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值