COFO::1475E Advertising Agency

Problem

Point

Design

Complexity

Code

#include<bits/stdc++.h>
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(int i = (a); i <(b); i++)
#define r_rep(i, a, b) for(int i = (a); i >(b); i--)
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;

ll nCx[1003][1003];
void _init() {
    nCx[1][0] = nCx[1][1] = 1;
    rep(i, 2, 1001) {
        nCx[i][0] = nCx[i][i] = 1;
        rep(j, 1, i) {
            nCx[i][j] = nCx[i-1][j-1] + nCx[i-1][j];
            nCx[i][j] %= MOD;
        }
    }
}
void solve() {
    ll n, k; cin >> n >> k;
    vector<pair<int,int> > v(1001, {0, 0});
    rep(i, 0, n) {
        int x; cin >> x;
        v[x].fi = x;
        v[x].se++;
    }
    sort(v.rbegin(), v.rend());
    
    ll ans = 0, cnted = 0;
    rep(i, 0, n) {
        if (v[i].se + cnted == k) {ans = 1; break;}
        else if (v[i].se + cnted < k) {cnted += v[i].se;}
        else {
            ll x = v[i].se, y = k - cnted;
            ans = nCx[x][y];
            break;
        }
    }
    cout << ans << '\n';
}
int main(){
    _init();
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int tc; cin >> tc; while(tc--) solve();
    return 0;
}