-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·82 lines (68 loc) · 1.6 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·82 lines (68 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
typedef double T;
using namespace std;
void printTable(vector<vector<T>> t)
{
cout << "========================" << endl;
for (int i = 1; i < t.size(); ++i)
{
for (int ii = 0; ii < t.size(); ++ii)
{
cout << t[i][ii] << " ";
}
cout << endl;
}
cout << endl;
}
int main(void)
{
ios::sync_with_stdio(false);
cout.precision(20);
int n;
cin >> n;
vector<T> score;
for (int i = 0; i < n; ++i)
{
T s;
cin >> s;
score.push_back(s);
}
vector<vector<T>> DP;
for (int stepsize = 0; stepsize < n; ++stepsize)
{
vector<T> row;
for (int i = 0; i < n; ++i)
{
row.push_back(-LLONG_MIN);
}
DP.push_back(row);
}
for (int stepsize = n - 1; stepsize >= 1; --stepsize)
{
for (int i = 0; i < n; ++i)
{
if (i == 0)
{
DP[stepsize][i] = score[i];
}
else
{
int offset = 0;
T best = -LLONG_MIN;
while (i - (stepsize + offset) >= 0 && stepsize + offset < n)
{
best = max(best, DP[stepsize + offset][i - (stepsize + offset)] + score[i]);
++offset;
}
DP[stepsize][i] = best;
}
}
}
T best = DP[1][n - 1];
for (int final_stepsize = 1; final_stepsize < n; ++final_stepsize)
{
best = max(best, DP[final_stepsize][n - 1]);
}
cout << best << endl;
return 0;
}