QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153766 | #7052. Xian Xiang | PetroTarnavskyi# | AC ✓ | 425ms | 4644kb | C++17 | 2.3kb | 2023-08-30 21:50:30 | 2023-08-30 21:50:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 10;
const int C = 18;
string vec[N][N];
int maskInRow[N][N][N], maskInCol[N][N][N];
int score[C][C];
int dp[1 << C];
vector<pair<int, int>> objects;
int calculateDP(int mask)
{
if (dp[mask] != -1)
return dp[mask];
int c = SZ(objects);
dp[mask] = 0;
FOR(i, 0, c)
{
if (((mask >> i) & 1) == 0)
continue;
FOR(j, i + 1, c)
{
if (((mask >> j) & 1) == 0)
continue;
auto [r1, c1] = objects[i];
auto [r2, c2] = objects[j];
int maskIJ = (1 << i) | (1 << j);
if (((maskInRow[r1][c1][c2] | maskInCol[c2][r1][r2]) & mask) == maskIJ || ((maskInCol[c1][r1][r2] | maskInRow[r2][c1][c2]) & mask) == maskIJ)
{
dp[mask] = max(dp[mask], calculateDP(mask ^ (1 << i) ^ (1 << j)) + score[i][j]);
}
}
}
return dp[mask];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n, m, k;
cin >> n >> m >> k;
objects.clear();
FILL(maskInRow, 0);
FILL(maskInCol, 0);
FILL(dp, -1);
FOR(i, 0, n)
FOR(j, 0, m)
{
cin >> vec[i][j];
if (vec[i][j][0] != '-')
{
maskInRow[i][j][j] = 1 << SZ(objects);
maskInCol[j][i][i] = 1 << SZ(objects);
objects.emplace_back(i, j);
}
}
FOR(i, 0, n) FOR(l, 0, m) FOR(r, l + 1, m)
maskInRow[i][r][l] = maskInRow[i][l][r] = maskInRow[i][l][r - 1] | maskInRow[i][r][r];
FOR(j, 0, m) FOR(l, 0, n) FOR(r, l + 1, n)
maskInCol[j][r][l] = maskInCol[j][l][r] = maskInCol[j][l][r - 1] | maskInCol[j][r][r];
vector<int> s(k + 1);
for (int& si : s)
cin >> si;
FOR(i, 0, SZ(objects))
FOR(j, i + 1, SZ(objects))
{
score[i][j] = 0;
int cnt = 0;
FOR(l, 0, k)
if (vec[objects[i].first][objects[i].second][l] == vec[objects[j].first][objects[j].second][l])
cnt++;
score[i][j] = s[cnt];
}
dp[0] = 0;
cout << calculateDP((1 << SZ(objects)) - 1) << "\n";
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4644kb
input:
3 2 2 3 aaa aaa bbb bbb 1 10 100 1000 2 3 3 aaa --- bbb bbb --- aaa 1 10 100 1000 1 4 3 aaa bba abb aaa 1 10 100 1000
output:
2000 2 1010
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 425ms
memory: 4644kb
input:
20 5 6 5 dbdaa cbcdc ----- dadad dbdaa bdbcc dbbdc aadcc dbbdc bdbad ----- ----- bccad abdab ----- bbdda ----- ddcbd adcbb ----- ----- ----- bdbcc ----- ----- ----- bbdda ----- ----- ----- 156 1333 2713 2853 3242 9881 6 7 4 ---- acaa ---- ---- ---- ---- ---- accc accc dcda ---- cbcb bbda ---- bbda d...
output:
49276 65059 38746 34398 39744 73820 31466 33302 43342 26102 45570 69039 61574 63160 66552 57157 69615 76688 79535 34563
result:
ok 20 lines