如果你用的逆向dp,且用的递归,请小心数据r=1,下面为我的递归代码。
int dp(int depth)
{
for (int i = 1; i <= depth; i++)
{
board[depth][i] += (board[depth + 1][i] > board[depth + 1][i + 1] ?
board[depth + 1][i] : board[depth + 1][i + 1]);
}
if (depth <= 1)
{
return board[depth][1];
}
dp(depth - 1);
}
请好好想想为什么退出判断是<=1而不是==1(最开始我用==1,结果就#3TLE)