QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#109026#6194. Knapsack ProblemLG_MonkeyRE 0ms0kbC++142.0kb2023-05-27 09:49:092023-05-27 09:49:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-27 09:49:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-27 09:49:09]
  • 提交

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;
								if (b1 < 10 && b2 < 10 && b3 < 10 && b4 < 10) 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:

2893

result: