QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335610#1169. Generate The ArrayAaronwrqTL 0ms3684kbC++141.0kb2024-02-23 17:07:272024-02-23 17:07:27

Judging History

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

  • [2024-02-23 17:07:27]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3684kb
  • [2024-02-23 17:07:27]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN 310
#define MAXK 300010
using namespace std;

int n, k, tot;
long long a[MAXN][MAXN], val[MAXN];
long long ans, now;
int id[MAXN];
vector<pair<long, long> > b[MAXN];
const long long inf = 0x3f3f3f3f3f3f3f3fll;

void dfs(const long long p) {
	if (p > n) {
		now = 0;
		for (int i = 1; i <= n; ++i) val[i] = b[i][id[i]].first, now -= b[i][id[i]].second;
		for (int i = 1; i <= n; ++i) for (int j = i; j <= n; ++j) {
			long long maxv = 0;
			for (int k = i; k <= j; ++k) maxv = max(maxv, val[k]);
			now += maxv * a[i][j];
		}
		ans = max(ans, now);
		return;
	}
	for (int i = 0; i < (int)b[p].size(); ++i) id[p] = i, dfs(p + 1);
	return;
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i) for (int j = i; j <= n; ++j) cin >> a[i][j];
	for (int i = 1; i <= n; ++i) {
		cin >> k; tot = 0;
		for (int j = 1; j <= k; ++j) {
			long long v, c; cin >> v >> c;
			b[i].push_back(make_pair(v, c));
		}
	}
	ans = -inf, dfs(1);
	cout << ans << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

5
1 0 2 2 0
0 2 2 0
2 2 2
1 2
0
2
0 27
1 19
2
7 25
1 1
2
8 7
4 18
2
8 7
4 4
2
0 25
4 26

output:

78

result:

ok 1 number(s): "78"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

2
1 1
1
2
1 100
2 50
1
1 100

output:

-145

result:

ok 1 number(s): "-145"

Test #3:

score: -100
Time Limit Exceeded

input:

300
791 246 453 104 979 932 79 625 573 836 378 302 70 70 5 424 656 262 799 471 107 998 874 452 227 26 435 896 816 466 372 596 212 931 459 879 265 686 216 996 553 304 547 680 540 961 931 16 549 445 512 545 781 542 930 295 247 359 927 631 978 738 409 364 443 980 286 13 576 356 462 909 821 703 489 10 5...

output:


result: