Dp 我的理解就是用不知道去推解不知道 能得到知道 (倒着推)
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int MAXN=105; int tower[MAXN][MAXN]; int max(int x,int y) {return x>y?x:y; } int solve (int n) {for(int i=n-1; i>=0; i--)for(int j=0; j<=i; j++){tower[i][j]+=max(tower[i+1][j],tower[i+1][j+1]);}return tower[0][0];} int main() {int n;while(~scanf("%d",&n)){memset(tower,0,sizeof(tower));for(int i=0; i<n; i++){for(int j=0; j<=i; j++){cin>>tower[i][j];}}int ans=solve(n);printf("%d\n",ans);} }