题目链接:
https://cn.vjudge.net/contest/275218#problem/I
题目:
There are n students working on a secret project, this project is very important and unique, so they decided to keep it safe, and protect it from leakage.
The students will put all the project's documents in a cabinet that has x locks, and each student will take a set of y unique keys, such that each key can open only one lock. The cabinet can be opened if and only if m or more of the students are present.
Each of the cabinet's lock has an infinite number of keys that can open it, and students may have different or similar sets of keys. In order to open the cabinet, zstudents must be presented (m ≤ z), such that these students have at least one key for each cabinet's lock.
Your task is to find minimum values of x and y. More formally, your task is to find what is the minimum number of locks needed and what is the minimum number of keys to the locks each student must carry such that the cabinet can be opened if and only if m or more of the students are present. Since these numbers are large, you need to print them modulo 109 + 7.
Input
The first line contains an integer T (1 ≤ T ≤ 105) specifying the number of test cases.
Each test case consists of a single line containing two integers n and m (1 ≤ m ≤ n ≤ 105), in which n is the number of students, and m is the minimum number of students that must be present to open the cabinet.
Output
For each test case, print a single line containing two integers x and y, in which xis the smallest number of locks needed, and y is the smallest number of keys to the locks each student must carry. Both numbers must be printed modulo 109 + 7.
Example
Input
4
3 2
2 2
5 4
5 3
Output
3 2
2 1
10 4
10 6
Note
In the first test case, there are 3 students, and at least 2 of them must present to open the cabinet. The optimal answer is to use 3 locks for the cabinet, such that each student will take 2 keys as follow: the 1st student takes keys of the 1st and 2nd locks, the 2nd student takes keys of the 1st and 3rd locks, and the 3rd student takes keys of the 2nd and 3rd locks. This distribution will ensure that at least two students must present in order to unlock all locks and open the cabinet.
题目大意:
有 n 个人,x把锁,(每个人有y把钥匙),要求最少有 m 个人在场才能打开这所有的x把锁,问 x y 的最小值分别是多少。(题目可能不好理解,看看Note和样例就明白了。)
题目分析:
有空再写,先空着~~~
代码:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int MAXN = (int)1e5 + 100;
ll f[MAXN], r[MAXN];
ll qPow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
void Init() {
f[0] = r[0] = 1;
for (int i = 1; i < MAXN; i++) {
f[i] = (f[i - 1] * i) % MOD;
r[i] = qPow(f[i], MOD - 2);
}
}
inline ll GetC(ll n, ll m) { return ((f[n] * r[m]) % MOD) * r[n - m] % MOD; }
int main() {
Init();
int T;
scanf("%d", &T);
while (T--) {
ll n, m;
scanf("%lld %lld", &n, &m);
printf("%lld %lld\n", GetC(n, m - 1), GetC(n - 1, m - 1));
}
return 0;
}