<meta name="viewport" content="width=device-width, initial-scale=1">
, но если его на сайте не будет, то моя верстка отобразиться не корректно<meta name="viewport" content="width=device-width, initial-scale=1">
или нет? int main()
{
std::ios_base::sync_with_stdio(false);
ifstream f("input.txt");
bntree b;
long long count;
f >> count;
long long power;
f >> power;
long long type;
f >> type;
long long sch = 1;
unordered_map<long long, long long> mp;
for (long long i = 1; i <= power; ++i) {
string val = to_string(i);
b.insert(sch, val);
mp.emplace(i, sch);
sch++;
}
sch = -1;
if (type == 1) {
for (long long i = 0; i < count; ++i) {
long long one;
f >> one;
long long key = mp[one];
long long ind = b.search(key);
cout << ind + 1 << " ";
b.eraseI(ind);
string strval = to_string(one);
b.insert(sch, strval);
mp[one] = sch;
sch--;
}
}
else {
for (long long i = 0; i < count; ++i) {
long long one;
f >> one;
long long key = b.getI(one - 1)->key;
string res = b.getI(one - 1)->val;
cout << res << " ";
b.erase(key);
b.insert(sch, res);
sch--;
}
}
return 0;
}
bool operator> (string& a, string& b) {
long long d1 = stoll(a);
long long d2 = stoll(b);
return d1 > d2;
}
bool operator< (string& a, string& b) {
long long d1 = stoll(a);
long long d2 = stoll(b);
return d1 < d2;
}
bool operator== (string& a, string& b) {
long long d1 = stoll(a);
long long d2 = stoll(b);
return d1 == d2;
}
int main()
{
ifstream f("input.txt");
bntree b;
long long count;
f >> count;
long long power;
f >> power;
long long type;
f >> type;
for (long long i = 1; i <= power; ++i) {
string key = to_string(sch);
string val = to_string(i);
b.insert(key,val);
mp.emplace(i,key);
sch++;
}
sch = -1;
if (type == 1) {
for (long long i = 0; i < count; ++i) {
long long one;
f >> one;
string key = mp[one];
long long ind = b.search(key);
cout << ind + 1 << " ";
b.erase(ind);
string newkey = to_string(sch);
sch--;
string strval = to_string(one);
b.insert(newkey, strval);
mp[one] = newkey;
}
}
else {
for (long long i = 0; i < count; ++i) {
long long one;
f >> one;
string key = b.get(one-1)->key;
string res = b.get(one-1)->val;
cout << res << " ";
b.erase(key);
string newkey = to_string(sch);
sch--;
b.insert(newkey,res);
}
}
return 0;
}
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <chrono> // for std::chrono functions
long long modExp(long long x, long long y, long long N)
{
if (y == 0) return 1;
long long z = modExp(x, y / 2, N);
if (y % 2 == 0)
return (z * z) % N;
else
{
long long zz{ (z * z) % N };
return (x * zz) % N;
}
}
long long modFactorial(int n, long long N)
{
static std::vector<long long> memory(251, -1);
if (n < 251)
{
if (memory[n] == -1)
{
memory[n] = (n == 1 || n == 0) ? 1 : (modFactorial(n - 1, N) * n) % N;
}
return memory[n];
}
else
return (modFactorial(n - 1, N) * n) % N;
}
long long revModFactorial(int n, long long N)
{
static std::vector<long long> revMemory(251, -1);
if (n < 251)
{
if (revMemory[n] == -1)
{
revMemory[n] = (revModFactorial(n + 1, N) * (n + 1)) % N;
}
return revMemory[n];
}
else
return modExp(modFactorial(n, N), N - 2, N);
}
long long modC(int n, int k, long long N) {
static std::vector< std::vector<long long>> modCmemory(251,
std::vector<long long>(251, -1));
if (n < k)
return 0;
else if (n == k)
return 1;
else if (modCmemory[n][k] == -1)
{
long long denum{ (revModFactorial(k, N) * revModFactorial(n - k, N)) % N };
modCmemory[n][k] = (modFactorial(n, N) * denum) % N;
}
return modCmemory[n][k];
}
int sumUpTo(int k, std::vector<int>& a)
{
static std::vector<int> sumUpToMemory(k + 1, -1);
if (sumUpToMemory[k] == -1)
{
if (k == 0)
sumUpToMemory[k] = 0;
else
{
int sum{};
sum = a[k] + sumUpTo(k - 1, a);
sumUpToMemory[k] = sum;
}
}
return sumUpToMemory[k];
}
long long DP(int k, int t, int i, std::vector<int>& a, long long N)
{
static std::vector<std::vector<std::vector<long long>>> DPmemory(51,
std::vector<std::vector<long long>>(251,
std::vector<long long>(101, -1)));
if ((k < 0) || (t < 0) || (i < -50) || (i > 50)) return 0;
if (DPmemory[k][t][i+50] == -1)
{
if (k == 0)
{
if ((t == 0) && (i == 0) ) DPmemory[k][t][i+50] = 1;
else DPmemory[k][t][i+50] = 0;
}
else
{
long long sum{};
int min{ std::min(a[k], t) };
for (int v{ 0 }; v <= min; ++v)
{
long long tempC{ (modC(t, v, N) * modC(sumUpTo(k, a) - t, a[k] - v, N)) % N };
if (tempC > 0)
sum = (sum + DP(k - 1, t - v, i - (v > 0) - (v < a[k]), a, N)* tempC) % N;
}
DPmemory[k][t][i+50] = sum;
}
}
return DPmemory[k][t][i+50];
}
int main()
{
//Input optimization
std::ios_base::sync_with_stdio(false);
//Reading from file
std::ifstream input("input.txt");
std::stringstream strStream;
strStream << input.rdbuf();
int n; //n - number of cardTypes
strStream >> n;
std::vector<int> deck(n + 1);
int deckSize{};
for (int cardType{ 1 }; cardType <= n; ++cardType)
{
strStream >> deck[cardType];
deckSize += deck[cardType];
}
long long N{ 1000000007 };
long long p{};
long long rq{ revModFactorial(deckSize, N) };
for (int cardType{ 1 }; cardType <= n; ++cardType)
{
rq = (rq * modFactorial(deck[cardType], N)) % N;
}
for (int i{ 1 }; i <= n; ++i)
{
p = (p + DP(n, deckSize / 2, 0, deck, N)) % N;
}
std::cout << (p * rq) % N << "\n";
return 0;
}
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <chrono> // for std::chrono functions
long long modExp(long long x, long long y, long long N)
{
if (y == 0) return 1;
long long z = modExp(x, y / 2, N);
if (y % 2 == 0)
return (z * z) % N;
else
{
long long zz{ (z * z) % N };
return (x * zz) % N;
}
}
long long modFactorial(int n, long long N)
{
static std::vector<long long> memory(251, -1);
if (n < 251)
{
if (memory[n] == -1)
{
memory[n] = (n == 1 || n == 0) ? 1 : (modFactorial(n - 1, N) * n) % N;
}
return memory[n];
}
else
return (modFactorial(n - 1, N) * n) % N;
}
long long revModFactorial(int n, long long N)
{
static std::vector<long long> revMemory(251, -1);
if (n < 251)
{
if (revMemory[n] == -1)
{
revMemory[n] = (revModFactorial(n + 1, N) * (n + 1)) % N;
}
return revMemory[n];
}
else
return modExp(modFactorial(n, N), N - 2, N);
}
long long modC(int n, int k, long long N) {
static std::vector< std::vector<long long>> modCmemory(251,
std::vector<long long>(251, -1));
if (n < k)
return 0;
else if (n == k)
return 1;
else if (modCmemory[n][k] == -1)
{
long long denum{ (revModFactorial(k, N) * revModFactorial(n - k, N)) % N };
modCmemory[n][k] = (modFactorial(n, N) * denum) % N;
}
return modCmemory[n][k];
}
int sumUpTo(int k, std::vector<int>& a)
{
static std::vector<int> sumUpToMemory(k + 1, -1);
if (sumUpToMemory[k] == -1)
{
if (k == 0)
sumUpToMemory[k] = 0;
else
{
int sum{};
sum = a[k] + sumUpTo(k - 1, a);
sumUpToMemory[k] = sum;
}
}
return sumUpToMemory[k];
}
long long DP(int k, int t, int i, std::vector<int>& a, long long N)
{
static std::vector<std::vector<std::vector<long long>>> DPmemory(51,
std::vector<std::vector<long long>>(251,
std::vector<long long>(101, -1)));
if ((k < 0) || (t < 0) || (i < 0) || (j < 0)) return 0;
if (DPmemory[k][t][i+50] == -1)
{
if (k == 0)
{
if ((t == 0) && (i == 0) && (j == 0)) DPmemory[k][t][i+50] = 1;
else DPmemory[k][t][i+50] = 0;
}
else
{
long long sum{};
int min{ std::min(a[k], t) };
for (int v{ 0 }; v <= min; ++v)
{
long long tempC{ (modC(t, v, N) * modC(sumUpTo(k, a) - t, a[k] - v, N)) % N };
if (tempC > 0)
sum = (sum + DP(k - 1, t - v, i - (v > 0) - (v < a[k]), a, N)* tempC) % N;
}
DPmemory[k][t][i+50] = sum;
}
}
return DPmemory[k][t][i+50];
}
int main()
{
//Input optimization
std::ios_base::sync_with_stdio(false);
//Reading from file
std::ifstream input("input.txt");
std::stringstream strStream;
strStream << input.rdbuf();
int n; //n - number of cardTypes
strStream >> n;
std::vector<int> deck(n + 1);
int deckSize{};
for (int cardType{ 1 }; cardType <= n; ++cardType)
{
strStream >> deck[cardType];
deckSize += deck[cardType];
}
long long N{ 1000000007 };
long long p{};
long long rq{ revModFactorial(deckSize, N) };
for (int cardType{ 1 }; cardType <= n; ++cardType)
{
rq = (rq * modFactorial(deck[cardType], N)) % N;
}
for (int i{ 1 }; i <= n; ++i)
{
p = (p + DP(n, deckSize / 2, 0, deck, N)) % N;
}
std::cout << (p * rq) % N << "\n";
return 0;
}