repl.it
@cream_puff_four/

Second Testing Thing

C++11

No description

fork
loading
Files
  • main.cpp
main.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	int arr[1000][1000] = {};
	int x, y, value = 1;
    while (x != 0 && y != 0 && value != 0) {
        cin >> x >> y >> value;
        arr[x][y] = value;
    }
	for (int i = n - 1; i >= 0; i --) {
		for (int j = n - 1; j >= 0; j --) {
		    if(i == n - 1 && j == n - 1) {
		        continue;
		    }
			if(i == n - 1) {
			    arr[i][j] += arr[i][j + 1];
			}
			else if (j == n - 1) {
			    arr[i][j] += arr[i + 1][j];
			}
			else {
			    arr[i][j] += max(arr[i + 1][j], arr[i][j + 1]);
			}
			for (int i = 0; i < n; i ++) {
			    for (int j = 0; j < n; j ++) {
			        cout << arr[i][j] << " ";
			    }
			    cout << endl;
			}
		}
	}
	cout << arr[0][0];
}