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
|
#include <iostream>
#include <vector>
using namespace std;
class CIS14
{
public:
int getMaxPoints(vector<vector<int>> &maze)
{
if (maze.empty()){
return 0;
}
for (int i = maze.size(); i > 0; --i)
{
for (int j = 0; j < (i - 1); ++j)
{
int x = maze[i-1].size();
int y = maze[i-2].size();
if (&maze[i-2][j]==nullptr)
{
return 0;
}
if (y >= x)
{
return 0;
}
else if (x > y)
{
maze[i-2][j] = maze[i-2][j] + std::max(maze[i-1][j], maze[i-1][j+1]);
}
else
return 0;
}
}
return maze[0][0];
}
};
int main()
{
CIS14 cis14;
vector<vector<int>> maze1 = {{2}, {4,1}, {5,3,8}, {1,6,7,3}, {1,2,3,4,5}, {1,2,3,4,5,6}};
vector<vector<int>> maze2 = {{2}, {4,1}, {0,0,0}, {0,0,0,0}};
vector<vector<int>> maze3 = {};
vector<vector<int>> maze4 = {{}, {}, {}};
vector<vector<int>> maze5 = {{2}, {4,1,5}, {5,3}, {1,6,7,3}};
cout << cis14.getMaxPoints(maze1) << endl;
cout << cis14.getMaxPoints(maze2) << endl;
cout << cis14.getMaxPoints(maze3) << endl;
cout << cis14.getMaxPoints(maze4) << endl;
cout << cis14.getMaxPoints(maze5) << endl;
return 0;
}
|