题目描述
小东所在公司要发年终奖,而小东恰好获得了最高福利,他要在公司年会上参与一个抽奖游戏,游戏在一个6*6的棋盘上进行,上面放着36个价值不等的礼物,每个小的棋盘上面放置着一个礼物,他需要从左上角开始游戏,每次只能向下或者向右移动一步,到达右下角停止,一路上的格子里的礼物小东都能拿到,请设计一个算法使小东拿到价值最高的礼物。
给定一个6*6的矩阵board,其中每个元素为对应格子的礼物价值,左上角为[0,0],请返回能获得的最大价值,保证每个礼物价值大于100小于1000。
int maxVal = INT_MIN;
int dx[2] = {0,1};
int dy[2] = {1,0};
void findCost(vector<vector<int> > board, vector<vector<bool>> table, int cur, int x ,int y)
{
if(x == 5 && y == 5)
{
maxVal = max(maxVal, cur);
return ;
}
for(int i = 0; i<2;i++)
{
int newx = x+dx[i];
int newy= y+dy[i];
if(newx>5||newy>5||table[newx][newy])
continue;
table[newx][newy] = 1;
findCost(board, table, cur+board[newx][newy],newx,newy);
table[newx][newy] = 0;
}
}
int getMost(vector<vector<int> > board) {
// write code here
vector<vector<bool>> table(6, vector<bool>(6, 0));
findCost(board, table, board[0][0], 0, 0);
return maxVal;
}