Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int analyse(int **iData, int **oData, int _high, int _width, int x, int y) {
- int returnValue = 0;
- if (oData[x][y] == -1) {
- int scoreX = -1, scoreY = -1;
- if (x != 0) {
- scoreX = analyse(iData, oData, _high, _width, x - 1, y);
- }
- if (y != _width - 1) {
- scoreY = analyse(iData, oData, _high, _width, x, y + 1);
- }
- if ( scoreX == -1 && scoreY == -1 ) {
- returnValue = 0;
- } else {
- if (scoreX > scoreY) {
- returnValue = scoreX;
- } else {
- returnValue = scoreY;
- }
- }
- oData[x][y] = iData[x][y] + returnValue;
- }
- return oData[x][y];
- }
- int main()
- {
- ifstream fin("turtle.in");
- int high = 0, width = 0;
- fin >> high >> width;
- int **a = new int*[high];
- int **scores = new int*[high];
- for (int i = 0; i < high; i++) {
- a[i] = new int[width];
- scores[i] = new int[high];
- for (int j = 0; j < width; j++) {
- fin >> a[i][j];
- scores[i][j] = -1;
- }
- }
- ofstream fout("turtle.out");
- fout << analyse(a, scores, high, width, high - 1, 0);
- for (int i = 0; i < high; i++) {
- delete[] a[i];
- delete[] scores[i];
- }
- delete[] a;
- delete[] scores;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement