Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve() throws IOException {
- int n = readInt();
- int size = n * (n + 1) / 2;
- this.graph = new List[size];
- for (int i = 0; i < size; i++) {
- graph[i] = new ArrayList<Integer>();
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j <= i; j++) {
- if (i * (i + 1) / 2 + j + i + 1 < size) {
- graph[i * (i + 1) / 2 + j].add(i * (i + 1) / 2 + j + i + 1);
- graph[i * (i + 1) / 2 + j].add(i * (i + 1) / 2 + j + i + 2);
- }
- }
- }
- this.init = readIntArray(size);
- out.println(dfs(0));
- }
- int[] init;
- int dfs(int from) {
- int max = -100000;
- for (int i : graph[from]) {
- max = maxInt(dfs(i), max);
- }
- if (max == -100000) {
- max = 0;
- }
- return max + init[from];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement