RT。
#include <stdio.h>
#include <vector>
template<typename Tp>
inline void Read(Tp &x) {
x = 0; int w = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') w = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= w;
}
#define mx(a, b) ((a) > (b) ? (a) : (b))
#define AddE(a, b) e[a].push_back(b)
const int N = 25; int n, x[N], f[N], pre[N];
std:: vector<int> e[N];
int main(void) {
Read(n); for (int i = 1; i <= n; ++i) Read(x[i]);
for (int i = 1, x; i < n; ++i)
for (int j = i + 1; j <= n; ++j) {
Read(x);
if (x) AddE(i, j), AddE(j, i);
}
int tot = 0, pos = 0;
for (int i = 1; i <= n; ++i) {
for (int j : e[i])
if (f[j] > f[i]) f[i] = f[j], pre[i] = j;
f[i] += x[i];
if (f[i] > tot) tot = f[i], pos = i;
}
for (; pos; printf("%d ", pos), pos = pre[pos]); printf("\n%d\n", tot);
return 0;
}
看出来记得踢我一脚。