简单题
View Code
#include < iostream > #include < cstdio > #include < cstdlib > #include < cstring > using namespace std; #define maxn 400 int n, ball[maxn][maxn], f[maxn][maxn]; int main(){ // freopen("t.txt", "r", stdin); scanf( " %d " , & n); for ( int i = 1 ; i <= n; i ++ ) for ( int j = 1 ; j <= i; j ++ ) scanf( " %d " , & ball[i][j]); for ( int i = 1 ; i <= n; i ++ ) for ( int j = 1 ; j <= i; j ++ ) f[i][j] = ball[i][j] + max(f[i - 1 ][j - 1 ], f[i - 1 ][j]); int ans = 0 ; for ( int i = 1 ; i <= n; i ++ ) ans = max(ans, f[n][i]); printf( " %d\n " , ans); return 0 ;}