QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165663 | #6849. Mr. Liang play Card Game | PPP# | AC ✓ | 11ms | 11944kb | C++17 | 2.1kb | 2023-09-05 20:38:02 | 2023-09-05 20:38:03 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m, R, p;
const int maxN = 105;
int a[maxN];
int V[maxN];
ll dp[maxN][maxN];
int lg[maxN];
ll f[maxN][maxN][maxN];
int cnt[maxN];
void solve() {
cin >> n >> m >> R >> p;
for (int i = 1; i <= m; i++) cnt[i] = 0;
lg[1] = 1;
for (int i = 2; i <= n; i++) {
lg[i] = -1;
if (i % 2 == 0 && lg[i / 2] != -1) {
lg[i] = lg[i / 2] + 1;
}
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
for (int i = 1; i <= m; i++) {
cin >> V[i];
}
for (int l = n; l >= 1; l--) {
for (int r = l; r <= n; r++) {
dp[l][r] = -1e18;
for (int k = 1; k <= cnt[a[r]]; k++) {
f[l][r][k] = -1e18;
}
if (l == r) {
dp[l][r] = V[a[l]];
f[l][r][1] = 0;
continue;
}
f[l][r][1] = 0;
for (int prv = l; prv < r; prv++) {
if (a[prv] == a[r]) {
for (int z = 1; z < cnt[a[r]]; z++) {
f[l][r][z + 1] = max(f[l][r][z + 1], f[l][prv][z] + dp[prv + 1][r - 1]);
}
}
}
for (int k = l; k < r; k++) {
dp[l][r] = max(dp[l][r], dp[l][k] + dp[k + 1][r]);
}
for (int k = l; k <= r; k++) {
ll coef = V[a[k]];
for (int D = 1; D <= (1 << (R - 1)) && D <= cnt[a[k]]; D *= 2) {
dp[l][r] = max(dp[l][r], f[l][k][D] + coef + dp[k + 1][r]);
coef *= p;
}
}
}
}
cout << dp[1][n] << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 11944kb
input:
50 55 2 3 8 2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 1 2 2 2 1 1 1 42126 55001 55 3 1 8 2 3 1 1 3 3 3 2 1 2 1 2 1 2 1 3 1 3 3 2 3 2 2 3 1 1 2 2 2 2 2 3 3 2 2 2 3 1 3 2 1 2 2 1 1 2 2 3 3 3 1 1 3 3 2 39105 57552 26545 55 2 3 9 2 1 2 2 2 2 2 2 2 2 ...
output:
38200162 2330529 69176157 3661875 7083386 1021147 334792 859244 1057821 276184 1182470 1200828 1475228 3028111 796232 331782 440245 952455 977955 1210135 51990 1172231 311282 1044444 773077 1426404 4815974 1239955 1144503 120368 84132 2230930 1259948 680475 528194 599850 861273 1739942 1319720 11729...
result:
ok 50 lines