QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#611047 | #7006. Rikka with Subsequences | yaoyanfeng | AC ✓ | 818ms | 4160kb | C++14 | 1.8kb | 2024-10-04 19:02:45 | 2024-10-04 19:02:50 |
Judging History
answer
/*
有点逆天了这题
cnt^3 显然拆成3个有序序列计数
设fijk表示三个序列,第一个结尾i,第二个j,第三个k
考虑转移相当于要求所有的 fi'j'k',mp[a[i']][i]=1
前缀和维护,具体的,每次dp,先把当前的fi{jk} 求一个二维前缀和,然后看着累加到前缀和s上。
sij的含义:首先ai=aj,然后表示的是所有颜色能转移到aj的东西的前缀和
666
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 205, mod = 1e9 + 7;
int T, n;
int a[N];
char mp[N][N];
void add(int &x, int y) {
x = x + y;
if (x >= mod) x -= mod;
return;
}
int f[N][N], sum[N][N], ret;
int qr(int x, int y) {
if (x < 0 || y < 0) return 0;
return f[x][y];
}
void solve() {
scanf("%d", &n), ret = 0;
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
for (int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) f[i][j] = sum[i][j] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
add(f[j][k], f[j - 1][k]), add(f[j][k], f[j][k - 1]), add(f[j][k], mod - f[j - 1][k - 1]);
}
}
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k)
if (mp[a[i - 1]][a[j]] == '1') add(sum[j][k], f[j - 1][k - 1]);
}
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
if (a[i] != a[j] || a[i] != a[k]) f[j][k] = 0;
else f[j][k] = sum[j][k] + 1;
add(ret, f[j][k]);
}
}
}
printf("%lld\n", ret);
return;
}
int main() {
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3828kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 818ms
memory: 4160kb
input:
20 195 4 5 4 3 2 4 3 5 1 5 4 3 4 3 1 5 4 4 5 2 2 2 2 4 1 5 3 4 1 1 1 2 1 1 5 5 4 5 4 5 5 4 5 2 1 2 5 4 5 1 1 3 1 2 2 3 3 5 2 3 3 1 4 4 2 4 2 4 3 4 1 1 1 4 3 5 1 1 3 2 2 5 1 3 1 5 1 5 5 3 5 3 3 2 5 1 3 2 4 1 5 5 1 3 3 2 4 2 3 3 3 4 1 3 3 3 5 5 1 1 4 2 5 1 2 5 4 3 5 1 5 5 5 4 2 2 5 3 2 3 4 1 3 2 1 5 3...
output:
806298135 541285042 48173297 222851978 875793336 100057791 156057874 129923599 551277543 874547790 544405786 653241411 521317929 370918040 803940504 969296122 806596012 469227084 338962879 194278629
result:
ok 20 lines