题号:1216
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<iostream> #include<algorithm> #include<string> #define INF 2e9 using namespace std; int n, arr[1005][1005]; int f[1005][1005]; int main(){ ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++){ for (int j = 1; j <= i; j++){ cin >> arr[i][j]; } } for (int i = 1; i <= n; i++){ for (int j = 1; j <= i; j++){ f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]) + arr[i][j]; } } int m = 0; for (int i = 1; i <= n; i++){ if (f[n][i] > m)m = f[n][i]; } cout << m; } |