0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

Compare commits

...

3 Commits

3 changed files with 150 additions and 0 deletions

51
Luogu/P1313/P1313.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
const int mod = 1e4 + 7;
int a, b, k, n, m;
int fac[N], inv[N];
int binpow(int a, int b) {
int res = 1;
a %= mod;
while (b) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
inline int C(int n, int m) {
return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
fac[0] = 1;
for (int i = 1; i <= 1000; i++) {
fac[i] = 1ll * fac[i - 1] * i % mod;
}
inv[0] = inv[1] = 1;
for (int i = 2; i <= 1000; i++) {
inv[i] = static_cast<long long>(mod - (mod / i)) * inv[mod % i] % mod;
}
for (int i = 2; i <= 1000; i++) {
inv[i] = static_cast<long long>(inv[i - 1]) * inv[i] % mod;
}
cin >> a >> b >> k >> n >> m;
cout << static_cast<long long>(C(k, n)) * binpow(a, n) % mod * binpow(b, m) % mod << endl;
return 0;
}

48
Luogu/P3807/P3807.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int t, n, m, p, fac[N], inv[N];
inline int C(int n, int m, int p) {
if (m > n) return 0;
return 1ll * fac[n] * inv[m] % p * inv[n - m] % p;
}
int lucas(int n, int m, int p) {
if (!m) return 1;
return static_cast<long long>(C(n % p, m % p, p)) * lucas(n / p, m / p, p) % p;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
cin >> n >> m >> p;
fac[0] = 1;
for (int i = 1; i <= 100000; i++) {
fac[i] = 1ll * fac[i - 1] * i % p;
}
inv[0] = inv[1] = 1;
for (int i = 2; i <= 100000; i++) {
inv[i] = static_cast<long long>(p - (p / i)) * inv[p % i] % p;
}
for (int i = 2; i <= 100000; i++) {
inv[i] = static_cast<long long>(inv[i - 1]) * inv[i] % p;
}
cout << lucas(n + m, n, p) << endl;
}
return 0;
}

51
Luogu/P6146/P6146.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <iostream>
#include <algorithm>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, s[N << 1], f[N];
std::pair<int, int> a[N];
int pow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
s[a[i].second]++;
}
std::sort(a + 1, a + 1 + n);
for (int i = 1; i <= n << 1; i++) {
s[i] += s[i - 1];
}
for (int i = 1; i <= n; i++) {
f[i] = (f[i - 1] * 2 % mod + pow(2, s[a[i].first - 1]) % mod) % mod;
}
cout << f[n] << endl;
return 0;
}