首先,数据范围给错了,n必须在10000以下,不然光是存储数组就会RE
其次,我们必须从下往上来算,这样才能有状态转移方程:
dp[i][j]=min(dp[i+1][j],dp[i+1][j+1],dp[i+1][j+2])+a[i][j]dp[i][j] = min(dp[i + 1][j], dp[i + 1][j + 1], dp[i + 1][j + 2]) + a[i][j]dp[i][j]=min(dp[i+1][j],dp[i+1][j+1],dp[i+1][j+2])+a[i][j]
因为每个都由左中右三个点过来
知道状态转移方程以后,事情就变得简单了:
时间复杂度:O(n2)O(n^2)O(n2)