#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; vector<vector<int>> S(n); for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ int a; cin >> a; S[i].push_back(a); } } vector<vector<int>> dp(n); for(int i = 0; i < n; i++){ dp[i] = vector<int>(i + 1, 1); } dp[0][0] = S[0][0]; for(int i = 1; i < n; i++){ for(int j = 0; j <= i; j++){ if (j == 0) { dp[i][j] = dp[i-1][j] * S[i][j]; } else if (j == i) { dp[i][j] = dp[i-1][j-1] * S[i][j]; } else { if(S[i][j] > 0){ dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) * S[i][j]; } else { dp[i][j] = min(dp[i-1][j], dp[i-1][j-1]) * S[i][j]; } } } } cout << *max_element(dp[n-1].begin(), dp[n-1].end()); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter