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

Compare commits

..

2 Commits

64 changed files with 376 additions and 0 deletions

103
S2OJ/1385/1385.cpp Normal file
View File

@ -0,0 +1,103 @@
#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
void solve() {
std::vector<int> st(3), ed(3);
std::string s;
for (int i = 0; i < 3; i++) {
std::string t;
cin >> t;
st[i] = s.size();
s += t;
ed[i] = s.size() - 1;
}
std::function<int(int)> id = [&](int x) -> int {
return std::distance(std::begin(ed), std::lower_bound(std::begin(ed), std::end(ed), x));
};
int n = s.size();
std::vector<std::vector<long long>>
f(n, std::vector<long long>(n)),
g(3, std::vector<long long>(n)),
h(3, std::vector<long long>(n));
long long w = 0, ans = 0;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (s[i] != s[j]) continue;
int id_i = id(i),
id_j = id(j);
if (id_i == 0 && id_j == 2) {
f[i][j] = 1;
}
f[i][j] += g[id_j][i]; // 加上右边块的贡献
f[i][j] += h[id_i][j]; // 加上左边块的贡献
if (id_i == 1 && id_j == 1) {
f[i][j] += w; // 加上两边来的贡献
}
if (i != st[id_i] && j != ed[id_j]) {
f[i][j] += f[i - 1][j + 1]; // 还在块内,不跳到下一块
}
if (id_i == 0 && id_j == 2) {
w += f[i][j]; // 如果在两边的块,更新贡献
}
if (id_j != 0 && i != ed[id_i]) {
g[id_j - 1][i + 1] += f[i][j]; // 更新到左边块的贡献
}
if (id_i != 2 && j != st[id_j]) {
h[id_i + 1][j - 1] += f[i][j]; // 更新到右边块的贡献
}
if (id_i == id_j) {
if (j - i + 1 <= 3) {
// j - i + 1 == 2: i, j 相邻,总长度为偶数
// == 3: i, j 之间还有一个字符,总长度为奇数
ans += f[i][j];
}
} else if (id_i + 1 == id_j) { // i 和 j 在相邻块中
ans += static_cast<long long>(
1 // i, j 之间不拼字符,总长度为偶数
+ (i != ed[id_i]) // 如果 i 不是块末尾,还可以在中间拼一个字符,总长度为奇数
+ (j != st[id_j]) // 如果 j 不是块开头,还可以在中间拼一个字符,总长度为奇数
)
* f[i][j];
}
}
}
ans += w * (ed[1] - st[1] + 1);
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) solve();
return 0;
}

BIN
S2OJ/1385/data/pali1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/pali9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1385/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

87
S2OJ/254/254.cpp Normal file
View File

@ -0,0 +1,87 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
const int mod = 9999973;
int n, m;
long long f[N][N][N]{1}, ans;
long long C(long long x) {
return x * (x - 1) / 2;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
// 不增加炮
for (int j = 0; j <= m; j++) {
for (int k = 0; j + k <= m; k++) {
f[i][j][k] = f[i - 1][j][k];
}
}
// 增加 1 个炮
//
// 从 1 个炮增加到 2 个炮
for (int j = 0; j <= m; j++) {
for (int k = 1; j + k <= m; k++) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j + 1][k - 1] * (j + 1) % mod) % mod;
}
}
// 增加 1 个炮
//
// 从 0 个炮增加到 1 个炮
for (int j = 1; j <= m; j++) {
for (int k = 0; j + k <= m; k++) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][k] * (m - j - k + 1) % mod) % mod;
}
}
// 增加 2 个炮
//
// 一列从 0 个炮增加到 1 个炮
// 一列从 1 个炮增加到 2 个炮
for (int j = 0; j <= m; j++) {
for (int k = 1; j + k <= m; k++) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j][k - 1] * j * (m - j - k + 1) % mod) % mod;
}
}
// 增加 2 个炮
//
// 两列从 0 个炮增加到 1 个炮
for (int j = 2; j <= m; j++) {
for (int k = 0; j + k <= m; k++) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j - 2][k] * C(m - j - k + 2) % mod) % mod;
}
}
// 增加 2 个炮
//
// 两列从 1 个炮增加到 2 个炮
for (int j = 0; j <= m; j++) {
for (int k = 2; j + k <= m; k++) {
f[i][j][k] = (f[i][j][k] + f[i - 1][j + 2][k - 2] * C(j + 2) % mod) % mod;
}
}
}
for (int i = 0; i <= m; i++) {
for (int j = 0; i + j <= m; j++) {
ans = (ans + f[n][i][j]) % mod;
}
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/254/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/254/data/wwxwwx9.out (Stored with Git LFS) Normal file

Binary file not shown.