zoukankan      html  css  js  c++  java
  • Gym

    D. Time to go back

     

    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

    比赛时组合数求错了,网上看到一种更好的组合数求法,记一下。
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #define ll long long
     6 using namespace std;
     7 int Mod = 1000000007;
     8 ll n,m,k,d;
     9 ll a[220],C[220][220];
    10 void getC(){
    11     memset(C,0,sizeof(C));
    12     for(int i = 0; i < 220; i ++){
    13         C[i][0] = 1;
    14         for(int j = 1; j <= i; j ++){
    15             C[i][j] = (C[i-1][j-1]+C[i-1][j])%Mod;
    16         }
    17     }
    18 }
    19 int main(){
    20     int t;
    21     getC();
    22     cin>>t;
    23     while(t--){
    24         cin>>n>>m>>k>>d;
    25         memset(a,0,sizeof(a));
    26         for(ll i = 1; i <= n; i ++)cin>>a[i];
    27         int cnt = count_if(a+1,a+n+1,bind2nd(greater_equal<int>(),d));
    28         ll ans = 0;
    29         for(ll i = m>=cnt?cnt:m; i >= k; i --){
    30             ans = (ans+(C[cnt][i]%Mod)*(C[n-cnt][m-i]%Mod))%Mod;
    31         }
    32         cout << ans%Mod << endl;
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    网站服务化
    网站服务化
    dubbo 服务化
    dubbo 服务化
    elk 搭建
    poj1840
    poj1840
    poj2299
    poj2299
    poj2388
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7197285.html
Copyright © 2011-2022 走看看