QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109025 | #6194. Knapsack Problem | LG_Monkey | RE | 0ms | 0kb | C++14 | 1.9kb | 2023-05-27 09:48:10 | 2023-05-27 09:48:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define pb push_back
#define se second
#define deb(x) cerr << #x << "=" << (x) << "; "
#define ll long long
int k, c[100], a[100];
ll dp[32][17][10][10][10][10];
signed main() {
int T;
cin >> T;
while (T--) {
memset(dp, 0, sizeof dp);
cin >> k;
for (int i = 0; i < k; i++) cin >> c[i];
for (int i = 0; i < k; i++) cin >> a[i];
for (int i = 0; i <= 30; i++) {
for (int j = 0; j < (1ll << k); j++) {
for (int a1 = 0; a1 < 10; a1++) {
for (int a2 = 0; a2 < 10; a2++) {
for (int a3 = 0; a3 < 10; a3++) {
for (int a4 = 0; a4 < 10; a4++) {
// x[j][i] = 0
dp[i][j + 1][a1][a2][a3][a4] = max(dp[i][j + 1][a1][a2][a3][a4], dp[i][j][a1][a2][a3][a4]);
// x[j][i] = 1
int b1 = a1, b2 = a2, b3 = a3, b4 = a4;
if (j & 1) b2 += 2;
if (j & 2) b2 += 2;
if (j & 4) b3 += 2;
if (j & 8) b4 += 2;
dp[i][j + 1][b1][b2][b3][b4] = max(dp[i][j + 1][b1][b2][b3][b4], dp[i][j][a1][a2][a3][a4] + c[j]);
}
}
}
}
}
for (int a1 = 0; a1 < 10; a1++) {
for (int a2 = 0; a2 < 10; a2++) {
for (int a3 = 0; a3 < 10; a3++) {
for (int a4 = 0; a4 < 10; a4++) {
bool flag = 1;
if (k >= 1) {
flag &= (a1 & 1) == (a[0] & (1ll << i));
}
if (k >= 2) {
flag &= (a2 & 1) == (a[1] & (1ll << i));
}
if (k >= 3) {
flag &= (a3 & 1) == (a[2] & (1ll << i));
}
if (k >= 4) {
flag &= (a4 & 1) == (a[3] & (1ll << i));
}
if (flag) {
ll x = dp[i][k][a1][a2][a3][a4];
dp[i + 1][0][a1 / 2][a2 / 2][a3 / 2][a4 / 2] = max(dp[i + 1][0][a1 / 2][a2 / 2][a3 / 2][a4 / 2], x);
}
}
}
}
}
}
cout << dp[31][0][0][0][0][0];
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
3 2 1 2 4 4 5 3 3226252 19270256 2430652 1187613 12496062 10286165 17494834 24 85 34 4 901133 6693218 13245489 14740234 16186210 11382783 19277321 3855635 16523184 10168517 16195031 971041 10303441 8395899 11618555 529321239 218214127 92942310 207467810
output:
28809558056